/* I2C LCD Operation [ストロベリー・リナックス] I2C Senser of temp. [LM73] PIC12F629 4MHz mikroC Ver4.15 Last M 12/26 整理 Used rom 898words 12/24 Sound_Pee 958words 12/23 Ver 3.0 LM-73 0.5'C steps 12/18 Sleeping Ver 2.0 688words 12/17 Interrupt 12/16 Custom Character Start 2010/11/24 by M.Kikuchi Config=0x3184 :BOD=off */ sbit Soft_I2C_Scl at GP4_bit; sbit Soft_I2C_Sda at GP5_bit; sbit Soft_I2C_Scl_Direction at TRISIO4_bit; sbit Soft_I2C_Sda_Direction at TRISIO5_bit; char Contrast = 0b111111; //2.4Vmin 0b111000; //2.8V+- // Contrast = 0b101100; //3.2V+- = 0b100000; //3.8V+- char TR0; //Second void Interrupt() { INTCON.GPIF=0; } void Lcd_Comd(char X1) { Soft_I2C_Start(); Soft_I2C_Write(0x7c); //I2C address Soft_I2C_Write(0x0); Soft_I2C_Write(X1); Soft_I2C_Stop(); Delay_us(30); } void Lcd_Data(char X1) { Soft_I2C_Start(); Soft_I2C_Write(0x7c); //I2C address Soft_I2C_Write(0x40); Soft_I2C_Write(X1); Soft_I2C_Stop(); Delay_us(30); } void Lcd_I2c_Set() { Delay_ms(40); Lcd_Comd(0x38); //Function Lcd_Comd(0x39); //Function Lcd_Comd(0x14); //internal OSC Lcd_Comd(0x40); //set Icon address Lcd_Comd(0x10); //Icon bit Lcd_Comd(0x70 | (Contrast & 0x0F)); //Contrast set Lcd_Comd(0x5C | ((Contrast >>4)& 3)); Lcd_Comd(0x6C); //FolloworControl Delay_ms(300); // Lcd_Comd(0x38); //Function again Lcd_Comd(0x08); Lcd_Comd(0x0C); //Display on Lcd_Comd(0x06); //Entry mode increment Lcd_Comd(0x01); //Clear Display Delay_ms(2); } void Lcd_Pos(const char *S) { while (*S) Lcd_Data(*S++); } const char character1[] = {0,0,14,31,31,14,0,0};// address 0 const char character2[] = {24,24,0,6,9,8,9,6}; // 1 ℃ void CustomChar() { char i; Lcd_Comd(0x40); // Start Address for (i = 0; i<= 7; i++) Lcd_Data (character1[i]); // Data 0 for (i = 0; i<=7; i++) Lcd_Data(character2[i]); // 1 } void LM73_set(char TSP,char TSD){ //TSP=Pointer TSD=Register Data Soft_I2C_Start(); Soft_I2C_Write(0x98); //I2C address Soft_I2C_Write(TSP); // Pointer Soft_I2C_Write(TSD); // Control Status 11bit Soft_I2C_Stop(); Delay_us(30); } void LM73_Read(){ char i,TR1,TR2,Temp,TDATA; Soft_I2C_Start(); Soft_I2C_Write(0x98); //I2C address Soft_I2C_Write(0x0); // Pointer // Soft_I2C_Start(); // repeated start signal Soft_I2C_Write(0x99); //I2C address +R TR1=Soft_I2C_Read(1); // 1=acknowledge signal TR2=Soft_I2C_Read(0); // 0=not acknowledge signal Soft_I2C_Stop(); // if (TR1==0xFF){ Lcd_Comd(0x8A); for(i=0;i<6;i++) Lcd_Data(' '); } else{ if (TR2 & 0x80) Temp=1; else Temp=0; TDATA=(((TR1 & 0x1F)<<1 )| Temp); //32-1℃ //Display Lcd_comd(0x8A); //address Lcd_Data((TDATA /10)+'0'); //10℃ Lcd_Data((TDATA %10)+'0'); //1℃ Lcd_Data('.'); // "." if ((TR2 & 0x40)==0x40) Lcd_Data(0x35); // 0.5 Steps else Lcd_Data(0x30); // 0 Lcd_Data(' '); Lcd_Data(0x01); // ℃ } } void Sound_pee(){ char i,j; for (j=0;j<6;j++){ for (i=0;i<255;i++){ //3KHz GP1_bit=1; Delay_uS(166); GP1_bit=0; Delay_uS(166); GP1_bit=1; Delay_uS(166); GP1_bit=0; Delay_uS(166); } Delay_ms(161); } TR0 +=2; } void main() { char cnt; char R1,R2,R3,R4; TRISIO=0b00001001; GPIO =0b00000100; //+LCD ON=bit2 SW=bit3 Sound=bit1 IOC =0b00001000; //+Interrupt On ChangePin while(1){ Soft_I2C_Init(); // set of I2C Lcd_I2c_Set(); // set of begin LCD CustomChar(); // set of LCD CustomChar LM73_set(4,0); // set of TEMPERATURE IC off LM73_set(1,0xFC); // one shot // Lcd_Comd(0xCA); //set line 2 Lcd_Pos("BY M.K"); TR0=0x2F; // for 0 start R1=0x30; R2=R1; R3=R1; R4=R1; // Timer set do { TR0++; //1sec if (TR0==0x39) LM73_set(1,0xFC); //one shot if (TR0==0x3A) { TR0=0x30; R1++; //10sec LM73_Read(); // Read of Temerature Data if (R1==0x36) { R1=0x30; R2++; //1min if (R2==0x3A) { R2=0x30; R3++; // 10 min if (R3==0x33) Sound_pee(); if (R3==0x36) { R3=0x30; //1h Sound_pee(); R4++; // if (R4==0x3A) R4=0x30; } } } } // set Line 1:Timer Lcd_Comd(0x81); Lcd_Data(R4); Lcd_Data(0x3A); // ":" Lcd_Data(R3); Lcd_Data(R2); Lcd_Data(0x3A); // ":" Lcd_Data(R1); Lcd_Data(TR0); Delay_ms(1102); //Tun この数字で時間を合わせる // 1時間(3600)で10秒程度の誤差になれば良い。温度電圧でクロックが変わる。 Lcd_Comd(0xC0); //set Line 2 dot display for (cnt=0x30; cnt<0x39; cnt++) { if (TR0==0x39) Lcd_Data(0x20); else { if (cnt<=TR0) Lcd_Data(0x00);//"*" else Lcd_Data(0x20); } } } while(GP3_bit==1) ; // SW-ON over // Power off & Sleep TRISIO=0xFF; // all input Delay_ms(500); while(GP3_bit==0) ; // KEY off INTCON=0b11001000; //GIE/PEIE/GPIE asm SLEEP ; // INTCON=0; //Interrupt off Delay_ms(500); while(GP3_bit==0) ; // KEY off TRISIO=0x09; } }