/* I2C LCD Operation 2 [ذů] PIC12F1822 mikroC Ver4.6 Last 2011/6/2 Used ROM : 738 (36%) Start 2010/11/24 Ver2=2011/5/22 by M.Kikuchi Config1=0x3F84:2=0x3213: 4MHz */ // SCL=RA1_bit SDA=RA2_bit unsigned int adt; unsigned char Contrast = 0b101100; //3.2V+- // Contrast = 0b111111; //2.4Vmin 0b111000; //2.8V+- // Contrast = 0b101100; //3.2V+- = 0b100000; //3.8V+- void Lcd_Comd(char X1) { I2C1_Start(); I2C1_Wr(0x7c); //I2C address I2C1_Wr(0x0); I2C1_Wr(X1); I2C1_Stop(); Delay_us(30); } void Lcd_Data(char X1) { I2C1_Start(); I2C1_Wr(0x7c); //I2C address I2C1_Wr(0x40); I2C1_Wr(X1); I2C1_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(0b101100) 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 ADC_MRead(char channel) { // PIC12F1822 4MHz(Fosc=100) ADCON1=0b11000011; //7bit=ADFM(h=2 l=8bit) //6.5.4bit=Fosc 1.0=FVR Buffer ADFVR1_bit=0; // FVRCON set 00=off [01=1.024V] ADFVR0_bit=1; // 10=2048V 11=4.098V FVREN_bit =1; //FVR on ADCON0=((channel & 3)<<2) & 0b111111100; //set of channel ADON_bit =1; //A/D module on while(FVRRDY==0); //Wait GO_bit =1; //start while(GO_bit==1); // OK ? ADON_bit =0; //end process FVREN_bit =0; adt=ADRESL + (unsigned int)(ADRESH <<8) - 620; // offset 600 } void LCD_set() { char da1,da2,da3,da4; // da1=adt/1000; da2=(adt-(da1*1000))/100; da3=(adt-(da1*1000)-(da2*100))/10; da4=adt-(da1*1000)-(da2*100)-(da3*10); if(da1==0) Lcd_Data(' '); else Lcd_Data(da1+'0'); Lcd_Data(da2+'0'); Lcd_Data(da3+'0'); Lcd_Data('.'); Lcd_Data(da4+'0'); Lcd_Data(1); //'.C } void main() { char cnt,TR0; char R1,R2,R3,R4; int adt; OSCCON=0b01101010; //*4MHz (1101+0+10=Internal) TRISA =0b00011001; //1=input PORTA =0b00000100; //+LCD ON=bit2 SW=bit3 Sound=bit1 ANSELA=0b00010001; //ADC channel 0/3 WPUA= 0; //ADC Pull UP 20Kohm off NOT_WPUEN_bit=1; //off OPTION_REG IOCAP =0b00001000; //+Interrupt On ChangePin /* IOCIF // while(1){ I2C1_Init(100000); Lcd_I2c_Set(); // set of begin LCD CustomChar(); // set of LCD CustomChar // 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 while(1) { TR0++; //1sec if (TR0==0x3A){ TR0=0x30; //TEST R1++; if(R1==0x36){ //10Sec R1=0x30; R2++; if(R2==0x3A) //1Min R2=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(1000); //Tuning Timer // 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); } } /* ADC_MRead(0); //A/D Vmater Lcd_Comd(0xCA); //LCD set address LCD_set(); */ Lcd_Comd(0x8A); //LCD set address ADC_MRead(3); //LM61BIZ LCD_set(); } } }