helloarloha
Newbie level 2
![Newbie level 2](/styles/images/ranks/alevel2.gif)
we are required to setup the PIC18F452 and enable the ADC module to read a temperature sensor uisng PIC...can anyone help to provide the code? thx in advance...
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
helloarloha said:we are required to setup the PIC18F452 and enable the ADC module to read a temperature sensor uisng PIC...can anyone help to provide the code? thx in advance...
program thermometer452
dim LCD_RS as sbit at RB4_bit
LCD_EN as sbit at RB5_bit
LCD_D4 as sbit at RB0_bit
LCD_D5 as sbit at RB1_bit
LCD_D6 as sbit at RB2_bit
LCD_D7 as sbit at RB3_bit
LCD_RS_Direction as sbit at TRISB4_bit
LCD_EN_Direction as sbit at TRISB5_bit
LCD_D4_Direction as sbit at TRISB0_bit
LCD_D5_Direction as sbit at TRISB1_bit
LCD_D6_Direction as sbit at TRISB2_bit
LCD_D7_Direction as sbit at TRISB3_bit
dim ADCResult as longword
dim value as word[3]
dim vstring as string[3]
sub procedure GlobInit
TRISB = 0
PORTB = 0
TRISA = 1
ADCON1 = $4E
LCD_Init
LCD_Cmd(_LCD_CLEAR)
LCD_Cmd(_LCD_CURSOR_OFF)
LCD_Out(1, 1, "Temp:")
LCD_Out(1, 15, "'C")
end sub
main:
GlobInit
while true
ADCResult = (ADC_Read(0) * 500) >> 10
value[0] = ADCResult div 100
value[1] = (ADCResult div 10) mod 10
value[2] = ADCResult mod 10
vstring[0] = value[0] + 48
vstring[1] = value[1] + 48
vstring[2] = value[2] + 48
LCD_Out(1, 10, vstring)
delay_ms(50)
wend
end.
unsigned long ADCResult;
unsigned int value[3];
char vstring[3];
void GlobInit(void){
TRISB = 0;
PORTB = 0;
TRISA = 1;
ADCON1 = 0x4E;
LCD_Config(&PORTB, 4, 5, 6, 3, 2, 1, 0);
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(1, 1, "Temp:");
LCD_Out(1, 15, "'C");
}
void main(){
GlobInit();
while (1){
ADCResult = (ADC_Read(0) * 500) >> 10;
value[0] = ADCResult / 100;
value[1] = (ADCResult / 10) % 10;
value[2] = ADCResult % 10;
vstring[0] = value[0] + 48;
vstring[1] = value[1] + 48;
vstring[2] = value[2] + 48;
LCD_Out(1, 10, vstring);
delay_ms(50);
}
}