/* PIC12F683 Experiment Board Project: Temp Data Logger by Raj */ // Variable Declaration unsigned int TempValue, address; char *temperature = "000", error; char Message1[] = "RajLog"; char Message2[] = "Samples="; char Message3[] = "Sampling Time=" ; char Message4[] = "1 Sec 1 Min 10 Min"; unsigned short i,j,t,k,SampleInterval, temp, Counter, Limit=0xF0,Stop, Send, Mem_Full, Reset; sbit LED at GP2_bit; sbit Start_Button at GP5_bit; sbit Stop_Button at GP4_bit; sbit Send_Button at GP3_bit; // Delay Routine void Get_Delay(int v){ for(j=0; j0){ for (p=2; p<=m+1; p++) { r = EEPROM_Read(p); // Read Temperature Byte2Char(r); Soft_UART_Write(248); Soft_UART_Write(67); LineFeed(); } } } // Interrupt Service Routine void interrupt(void){ if (INTCON.GPIF == 1) { // If Start is Pressed if(Start_Button == 0) { Delay_ms(50); LED = 1; do{ } while(Start_Button != 1); Stop = 0; } // If Stop is Pressed if(Stop_Button == 0) { Delay_ms(50); do{ LED=1; } while(Stop_Button != 1); Stop = 1; Delay_ms(250); LED=0; } // If Send Button is pressed if(Send_Button == 0) { Delay_ms(50); i = 0; do{ Delay_ms(50); i = i+1; if(i > 20) { Send = 0; Reset = 1; LED = 1; } else Send = 1; } while(Send_Button != 1); } } INTCON.GPIF = 0; // Clear interrupt flag }//end ISR // Main Function void main() { short z=-1; CMCON0 = 7; // Disable Comparators //OPTION_REG = 0x40; TRISIO = 0x39; // 0011 1001 GPIO 0, 3, 4, 5 Inputs; Rest are O/Ps ANSEL = 0x00; Stop = 1; // No Data Logging at beginning, Start =0 Send = 0; // Send=1 starts sending data to UART Mem_Full = 0; // EEPROM Full flag is cleared Reset = 0; //t = 0; Blink_Led(); // Blinking at the start Counter = EEPROM_Read(0x00); // Read Counter Value if(Counter == 0xff) Counter = 0; // Define GPIO.0 as UART Rx, and 1 as Tx error = Soft_UART_Init(&GPIO,0, 1, 9600, 0 ); // If any buttons are pressed: Programming Mode while(!Start_Button) { z=0; LED = 1; } while(!Stop_Button) { z=6; LED = 1; } while(!Send_Button) { z=12; LED = 1; } if (z>=0) { EEPROM_Write(0x01,z); Blink_Led(); } SampleInterval = EEPROM_Read(0x01); // Read Sample Time if(SampleInterval==255) SampleInterval=0; INTCON.GIE = 1; // enable Global interrupts INTCON.GPIE = 1; // enable on change interrupts IOC = 0x38; //Interrupt on change, pins GPIO 3,4,5 do { if((Counter < Limit) && (Stop ==0)){ //--- perform temperature reading Ow_Reset(&GPIO, 0); // Onewire reset signal Ow_Write(&GPIO, 0, 0xCC); // Issue command SKIP_ROM Ow_Write(&GPIO, 0, 0x44); // Issue command CONVERT_T INTCON.GIE = 1; Get_Delay(10); // If this delay is less than 500ms, you will see the first reading on LCD //85C which is (if you remember from my article on DS1820) //a power-on-reset value. Ow_Reset(&GPIO, 0); Ow_Write(&GPIO, 0, 0xCC); // Issue command SKIP_ROM Get_Delay(10); Ow_Write(&GPIO, 0, 0xBE); // Issue command READ_SCRATCHPAD // Read Byte 0 from Scratchpad TempValue = Ow_Read(&GPIO, 0); // Then read Byte 1 from Scratchpad and shift 8 bit left and add the Byte 0 TempValue = (Ow_Read(&GPIO, 0) << 8) + TempValue; temp=TempValue >> 1; INTCON.GIE = 0; EEPROM_Write(Counter+2,temp); Counter =Counter + 1; EEPROM_Write(0x00,Counter); INTCON.GIE = 1; Blink_Led(); Sample_Delay(SampleInterval); } else if((Counter >=Limit) && (Stop==0)) { Mem_Full = 1; LED = 1; Get_Delay(20); LED = 0; Stop = 1; } if(Send){ INTCON.GPIE = 0; //Disable all interrupts while transmitting Send_Data(); Send=0; LED=0; INTCON.GPIE = 1; // Resume interrupt again } if (Reset == 1) { INTCON.GPIE = 0; //Disable all interrupts while Reset for(address=0; address<=Limit+2;address++){ EEPROM_Write(address,0x00); } Reset = 0; Stop = 1; LED = 0; Counter=0; SampleInterval = 0; INTCON.GPIE = 1; // Resume interrupt again } delay_ms(50); } while(1); }