Shoaib Khan
Newbie level 4
Code:
#define hbit portc.f0
#define sw1 portd.f0
//==============================================
unsigned int adc_rd0;
unsigned char ch;
void get_ad();
void get_hb();
void disp_hb();
long tlong;
unsigned char cnt=0,indh=0,ind=0,cnt2=0;
//==============================================================
unsigned int address;
unsigned char d1a,d2a,d3a;
unsigned char d1b,d2b,d3b;
unsigned char d1c,d2c,d3c;
unsigned char d1,d2,d3;
void main()
{
DELAY_MS(500);
ADCON1=0b00000110;
Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Cmd(Lcd_Clear);
ADCON1 = 0x82; // configure VDD as Vref, and analog channels
TRISA = 0xFF; // designate PORTA as input
TRISD=0X00;
trisc.f0=1;
trisd.f0=1;
Lcd_Custom_Out(1,2,"RIPAH INTERNATIONAL ");
DELAY_MS(1000);
Lcd_Custom_Cmd(Lcd_Clear);
address =0;
d1a=Eeprom_Read(address);
address =1;
d2a=Eeprom_Read(address);
address =2;
d3a=Eeprom_Read(address);
address =3;
d1b=Eeprom_Read(address);
address =4;
d2b=Eeprom_Read(address);
address =5;
d3b=Eeprom_Read(address);
address =6;
d1c=Eeprom_Read(address);
address =7;
d2c=Eeprom_Read(address);
address =8;
d3c=Eeprom_Read(address);
// Lcd_Custom_Out(2,2,"TEMPERATURE");
while(1){
if(sw1==0) {
Lcd_Custom_Cmd(Lcd_Clear);
address =0;
d1a=Eeprom_Read(address);
address =1;
d2a=Eeprom_Read(address);
address =2;
d3a=Eeprom_Read(address);
DELAY_MS(1000);
address =3;
d1b=Eeprom_Read(address);
address =4;
d2b=Eeprom_Read(address);
address =5;
d3b=Eeprom_Read(address);
address =6;
d1c=Eeprom_Read(address);
address =7;
d2c=Eeprom_Read(address);
address =8;
d3c=Eeprom_Read(address);
Lcd_Custom_Chr(1,2,48+d1a);
Lcd_Custom_Chr(1,3,48+d2a);
Lcd_Custom_Chr(1,4,48+d3a);
Lcd_Custom_Chr(1,10,48+d1b);
Lcd_Custom_Chr(1,11,48+d2b);
Lcd_Custom_Chr(1,12,48+d3b);
Lcd_Custom_Chr(2,2,48+d1c);
Lcd_Custom_Chr(2,3,48+d2c);
Lcd_Custom_Chr(2,4,48+d3c);
DELAY_MS(3000);
while(sw1==0);
Lcd_Custom_Cmd(Lcd_Clear);
DELAY_MS(1000);
}//get_ad();
get_hb();
// Lcd_Custom_Cmd(Lcd_Clear);
DELAY_MS(2000);
disp_hb();
DELAY_MS(2000);
// disp_hb();
}
}
//==================================================
void disp_hb() {
cnt=cnt*6;
tlong=cnt;
Lcd_Custom_Chr(1,1,'h');
LCD_Custom_Chr_CP('b');
LCD_Custom_Chr_CP('=');
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(1,4,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
d1=ch;
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
d2=ch;
LCD_Custom_Chr_CP(48+ch);
ch = tlong % 10; // extract 0.01 volts digit
d3=ch;
LCD_Custom_Chr_CP(48+ch);
cnt2++;
if(cnt2>3)cnt2=1;
if(cnt2==1){
Eeprom_Write(0,d1 );
Eeprom_Write(1,d2 );
Eeprom_Write(2, d3);
}
if(cnt2==2){
Eeprom_Write(3,d1 );
Eeprom_Write(4,d2 );
Eeprom_Write(5, d3);
}
if(cnt2==3){
Eeprom_Write(6,d1 );
Eeprom_Write(7,d2 );
Eeprom_Write(8, d3);
}
}
void disp_hb2() { /////with out multiply
// cnt=cnt*6;
tlong=cnt;
Lcd_Custom_Chr(2,1,'h');
LCD_Custom_Chr_CP('b');
LCD_Custom_Chr_CP('=');
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(2,4,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = tlong % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
}
void get_hb() {
unsigned char i=0,j=0;
cnt=0;
Lcd_Custom_Out(3,1," ");
Lcd_Custom_Chr(3,1,'>');
for(j=0;j<30;j++) {
delay_ms(100);
disp_hb2();
if(hbit==0) {
cnt++;
while(hbit==0);
}
}
//
}
void get_ad()
{
adc_rd0 = ADC_read(0);
Delay_ms(500);
tlong = (long)adc_rd0 * 5000;
tlong = tlong / 1023;
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(1,10,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
Delay_ms(500);
LCD_Custom_Chr_CP('c');
}#define hbit portc.f0
#define sw1 portd.f0
//==============================================
unsigned int adc_rd0;
unsigned char ch;
void get_ad();
void get_hb();
void disp_hb();
long tlong;
unsigned char cnt=0,indh=0,ind=0,cnt2=0;
//==============================================================
unsigned int address;
unsigned char d1a,d2a,d3a;
unsigned char d1b,d2b,d3b;
unsigned char d1c,d2c,d3c;
unsigned char d1,d2,d3;
void main()
{
DELAY_MS(500);
ADCON1=0b00000110;
Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTB,2,0,3);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Cmd(Lcd_Clear);
ADCON1 = 0x82; // configure VDD as Vref, and analog channels
TRISA = 0xFF; // designate PORTA as input
TRISD=0X00;
trisc.f0=1;
trisd.f0=1;
Lcd_Custom_Out(1,2,"RIPAH INTERNATIONAL ");
DELAY_MS(1000);
Lcd_Custom_Cmd(Lcd_Clear);
address =0;
d1a=Eeprom_Read(address);
address =1;
d2a=Eeprom_Read(address);
address =2;
d3a=Eeprom_Read(address);
address =3;
d1b=Eeprom_Read(address);
address =4;
d2b=Eeprom_Read(address);
address =5;
d3b=Eeprom_Read(address);
address =6;
d1c=Eeprom_Read(address);
address =7;
d2c=Eeprom_Read(address);
address =8;
d3c=Eeprom_Read(address);
// Lcd_Custom_Out(2,2,"TEMPERATURE");
while(1){
if(sw1==0) {
Lcd_Custom_Cmd(Lcd_Clear);
address =0;
d1a=Eeprom_Read(address);
address =1;
d2a=Eeprom_Read(address);
address =2;
d3a=Eeprom_Read(address);
DELAY_MS(1000);
address =3;
d1b=Eeprom_Read(address);
address =4;
d2b=Eeprom_Read(address);
address =5;
d3b=Eeprom_Read(address);
address =6;
d1c=Eeprom_Read(address);
address =7;
d2c=Eeprom_Read(address);
address =8;
d3c=Eeprom_Read(address);
Lcd_Custom_Chr(1,2,48+d1a);
Lcd_Custom_Chr(1,3,48+d2a);
Lcd_Custom_Chr(1,4,48+d3a);
Lcd_Custom_Chr(1,10,48+d1b);
Lcd_Custom_Chr(1,11,48+d2b);
Lcd_Custom_Chr(1,12,48+d3b);
Lcd_Custom_Chr(2,2,48+d1c);
Lcd_Custom_Chr(2,3,48+d2c);
Lcd_Custom_Chr(2,4,48+d3c);
DELAY_MS(3000);
while(sw1==0);
Lcd_Custom_Cmd(Lcd_Clear);
DELAY_MS(1000);
}//get_ad();
get_hb();
// Lcd_Custom_Cmd(Lcd_Clear);
DELAY_MS(2000);
disp_hb();
DELAY_MS(2000);
// disp_hb();
}
}
//==================================================
void disp_hb() {
cnt=cnt*6;
tlong=cnt;
Lcd_Custom_Chr(1,1,'h');
LCD_Custom_Chr_CP('b');
LCD_Custom_Chr_CP('=');
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(1,4,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
d1=ch;
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
d2=ch;
LCD_Custom_Chr_CP(48+ch);
ch = tlong % 10; // extract 0.01 volts digit
d3=ch;
LCD_Custom_Chr_CP(48+ch);
cnt2++;
if(cnt2>3)cnt2=1;
if(cnt2==1){
Eeprom_Write(0,d1 );
Eeprom_Write(1,d2 );
Eeprom_Write(2, d3);
}
if(cnt2==2){
Eeprom_Write(3,d1 );
Eeprom_Write(4,d2 );
Eeprom_Write(5, d3);
}
if(cnt2==3){
Eeprom_Write(6,d1 );
Eeprom_Write(7,d2 );
Eeprom_Write(8, d3);
}
}
void disp_hb2() { /////with out multiply
// cnt=cnt*6;
tlong=cnt;
Lcd_Custom_Chr(2,1,'h');
LCD_Custom_Chr_CP('b');
LCD_Custom_Chr_CP('=');
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(2,4,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = tlong % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
}
void get_hb() {
unsigned char i=0,j=0;
cnt=0;
Lcd_Custom_Out(3,1," ");
Lcd_Custom_Chr(3,1,'>');
for(j=0;j<30;j++) {
delay_ms(100);
disp_hb2();
if(hbit==0) {
cnt++;
while(hbit==0);
}
}
//
}
void get_ad()
{
adc_rd0 = ADC_read(0);
Delay_ms(500);
tlong = (long)adc_rd0 * 5000;
tlong = tlong / 1023;
ch = tlong / 1000; // extract volts digit
Lcd_Custom_Chr(1,10,48+ch);
ch = (tlong / 100) % 10; // extract 0.1 volts digit
LCD_Custom_Chr_CP(48+ch);
ch = (tlong / 10) % 10; // extract 0.01 volts digit
LCD_Custom_Chr_CP(48+ch);
Delay_ms(500);
LCD_Custom_Chr_CP('c');
}
FINDING IT