The PIC16F630
PIC16F630 is an 8-bit PICMicro released a decade a go. I bought a dozen of it for a simple project at a company at that time. So fa, I still have them left in my components storage box.
It's a 14-pin device with a DIP package enable good choice for hobbyist prototyping. The device typically supplied from 2.0 V to 5.5 V, normally 5 V is preferred for most peripheral device interfacing.
The program memory is 1024 words, with 64 bytes of internal SRAM. The auxiliary non-volatile memory EEPROM is 128 bytes.
It could clock up to 20 MHz. However with ease of prototyping and spacing saving, we can use it's internal RC oscillator that could clock up to 4 MHz with 1% error.
In this example, reading a temperature from one-wire device and just making a display, selecting this device is more economics.
The DS18S20 1-Wire Digital Temperature Sensor
DS18S20 is digital thermometer come with only three pins, two supply pin and one bi-directional data pin.
DS18S20 sample picture an pin diagram |
The device comes with both TO-92 and SMD package. A TO-92 is preferred for most student and hobbyist prototyping.
Temperature resolution is 9-bit. The temperature conversion ranges from -55 to +125 degree Celsius. The result includes one bit of fraction with the fraction number of 0.5 degree Celsius.
It needs a DC supply voltage from 3.0 V to 5.5 V. The data DQ pin is open-drain, thus requires a pull up resistor with the resistance from 4.7 to 10 kOhm depending on the wire length.
One-wire protocol made by the manufacturer requires a good embedded programming skill. It needs a precise timing, and there a lot of device command such as a Skip ROM and a Read Scratchpad command.
For a single device connection, the reading process is simpler. A single DS18S20 device temperature reading flow list below.
A screen shot from device datasheet. Here there's a single DS18S20 connected on the bus. |
CCS PICC Programming And Interfacing
CCS PICC 1-Wire Driver
- data = touch_read_bit() Reads one bit from a touch device
- data = touch_read_BYTE() Reads one byte from a touch device.
- ok = touch_write_bit(data) Writes one bit to a touch device and returns true if all went ok. A false indicates a collision with another device.
- ok = touch_write_byte(data) - Writes one byte to a touch device and returns true if all went ok. A false indicates a collision with another device.
- present = touch_present() - Issues a reset and returns true if the touch device is there.
- reset_pulse() - Issues a reset and waits for a present pulse.
Programming And Circuit Simulation
Schematic Diagram |
#include<16f630.h>
#fuses INTRC_IO,NOMCLR
#use delay(clock=4000000)
#define TOUCH_PIN PIN_A5
#include<touch.c>
#define LCD_ENABLE_PIN PIN_C1
#define LCD_RS_PIN PIN_A0
#define LCD_RW_PIN PIN_C0
#define LCD_DATA4 PIN_C2
#define LCD_DATA5 PIN_C3
#define LCD_DATA6 PIN_C4
#define LCD_DATA7 PIN_C5
#include<LCD.c>
byte buffer[2];
byte tempDecimal,tempFraction;
void temperatureRead(void){
if(touch_present()) {
//Skip ROM
touch_write_byte(0xCC);
//Convert T
touch_write_byte (0x44);
output_high(TOUCH_PIN);
delay_ms(1000);
touch_present();
//Skip ROM
touch_write_byte(0xCC);
//Read Scratchpad
touch_write_byte (0xBE);
//LSB
buffer[0] = touch_read_byte();
//MSB
buffer[1] = touch_read_byte();
}
}
void main() {
setup_comparator(NC_NC_NC_NC);
lcd_init();
lcd_gotoxy(1,1);
printf(LCD_PUTC," Temperature: ");
temperatureRead();
delay_ms(1000);
while (TRUE) {
temperatureRead();
tempDecimal=buffer[0]>>1;
tempFraction=buffer[0]&0x01;
if(buffer[1]==0xFF) tempDecimal=(~buffer[0]>>1)+1;
if(tempFraction==0x01) tempFraction=5;
else tempFraction=0;
lcd_gotoxy(1,2);
printf(LCD_PUTC," %c%d.%d %cC ",buffer[1]?'-':' ',tempDecimal,tempFraction,223);
}
}
Simulation Screen Shot |
No comments:
Post a Comment