dabby21
Advanced Member level 4
- Joined
- Aug 8, 2011
- Messages
- 114
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,296
- Location
- Philippines
- Activity points
- 2,232
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
float temp;
char i,txt[15];
unsigned int temp_res;
unsigned int quanta=0.488;
void Move_Delay() { // Function used for text moving
Delay_ms(500); // You can change the moving speed here
}
void main(){
ADCON1 = 0x0E;
ADCON0 = 0x00; // Set PORTA.0 To analog And all others digital
ADCON2 = 0x8A; // Set PORTA analog And right justify result
TRISA = 0xFF;
TRISB = 0x00;
PORTB = 0x00;
LATB = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Temperature :");
Lcd_Chr(2,8,223); // Different LCD displays have different
// char code for degree
Lcd_Chr(2,9,'C'); // Display "C" for Celsius
ADC_Init(); // Initialize ADC
do{
temp_res = ADC_Read(0);
temp= temp_res * quanta;
FloatToStr(temp, txt); // Convert temperature to string
Lcd_Out(2,3,txt);
Delay_Ms(300);
} while(1);
/* Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,6,txt3); // Write text in first row
Lcd_Out(2,6,txt4); // Write text in second row
Delay_ms(2000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,1,txt1); // Write text in first row
Lcd_Out(2,5,txt2); // Write text in second row
Delay_ms(2000);
// Moving text
for(i=0; i<4; i++) { // Move text to the right 4 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
while(1) { // Endless loop
for(i=0; i<8; i++) { // Move text to the left 7 times
Lcd_Cmd(_LCD_SHIFT_LEFT);
Move_Delay();
}
for(i=0; i<8; i++) { // Move text to the right 7 times
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Move_Delay();
}
} */
}
hello,
Does temp_res follow the LM35 value change ?
you better had to write :
Temp=(float)temp_res * quanta;
hello,
When you change the value on LM35 , value is in °C ?
does the AN0 in mV value change also ?
Try to display the temp_res value on lcd instead of the float value.
WordToStr(temp_res,txt);
also, Initialize the quanta value in the main . or declare it as constant value.
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void main(){
float temp;
char txt[15];
unsigned int temp_res;
const int quanta=0.488;
ADCON1 = 0x0E;
ADCON0 = 0x00; // Set PORTA.0 To analog And all others digital
ADCON2 = 128; // Set PORTA analog And right justify result
TRISA = 0xFF;
TRISB = 0x00;
PORTB = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Temperature :");
Lcd_Chr(2,8,223); // Different LCD displays have different
// char code for degree
Lcd_Chr(2,9,'C'); // Display "C" for Celsius
ADC_Init(); // Initialize ADC
do{
temp_res = ADC_Read(0);
temp= temp_res * quanta;
WordToStr(temp, txt); // Convert temperature to string
Lcd_Out( 2, 3 , txt);
Delay_Ms(500);
} while(1);
}
float quanta;
quanta=0.488;
....
CMCON=0;
ADCON0=0x01; //enable ADC ,Set PORTA.0 To analog And all others digital
ADCON1 = 0x0E;
ADCON2 = 128; // Set PORTA analog And right justify result
etc ....
do{
Lcd_Cmd(_LCD_CLEAR);
temp_res = 1000;
temp= (float) temp_res * quanta;
FloatToStr(temp, txt); // Convert temperature to string
Lcd_Out(1,3,txt);
temp_res =ADC_Read(0);
temp= (float) temp_res * quanta;
FloatToStr(temp, txt); // Convert temperature to string
Lcd_Out(2,3,txt);
Delay_Ms(2000);
} while(1);
sirs,
good day,
im working a simulation on LM35 through pic and output the results in LCD.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 // LCD module connections sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; // End LCD module connections float temp; char i,txt[15]; unsigned int temp_res; unsigned int quanta=0.488; void Move_Delay() { // Function used for text moving Delay_ms(500); // You can change the moving speed here } void main(){ ADCON1 = 0x0E; ADCON0 = 0x00; // Set PORTA.0 To analog And all others digital ADCON2 = 0x8A; // Set PORTA analog And right justify result TRISA = 0xFF; TRISB = 0x00; PORTB = 0x00; LATB = 0x00; Lcd_Init(); // Initialize LCD Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1, 1, "Temperature :"); Lcd_Chr(2,8,223); // Different LCD displays have different // char code for degree Lcd_Chr(2,9,'C'); // Display "C" for Celsius ADC_Init(); // Initialize ADC do{ temp_res = ADC_Read(0); temp= temp_res * quanta; FloatToStr(temp, txt); // Convert temperature to string Lcd_Out(2,3,txt); Delay_Ms(300); } while(1); /* Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off Lcd_Out(1,6,txt3); // Write text in first row Lcd_Out(2,6,txt4); // Write text in second row Delay_ms(2000); Lcd_Cmd(_LCD_CLEAR); // Clear display Lcd_Out(1,1,txt1); // Write text in first row Lcd_Out(2,5,txt2); // Write text in second row Delay_ms(2000); // Moving text for(i=0; i<4; i++) { // Move text to the right 4 times Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); } while(1) { // Endless loop for(i=0; i<8; i++) { // Move text to the left 7 times Lcd_Cmd(_LCD_SHIFT_LEFT); Move_Delay(); } for(i=0; i<8; i++) { // Move text to the right 7 times Lcd_Cmd(_LCD_SHIFT_RIGHT); Move_Delay(); } } */ }
upon researching, i have come up the above code, outputting the string temperature and character to the LCD was good, but when i try to change the result of LM35 in protues, it does not change the result on the LCD.\
heres my simulation on proteus sirs. thanks in advance
// LCD module connections
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// End LCD module connections
void main(){
float temp;
char txt[15];
unsigned int temp_res;
float quanta=0.488;
ADCON1 = 0x0E;
ADCON0 = 0x00; // Set PORTA.0 To analog And all others digital
/*
ADCON2
*ADC Result Right Justified.
*Acquisition Time = 2TAD
*Conversion Clock = 32 Tosc
*/
ADCON2=0b10001010;
CMCON = 0x07 ; // Disbale comparators
TRISA = 0xFF;
TRISB = 0x00;
PORTB = 0x00;
ADCON0.ADON=1;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Temperature :");
Lcd_Chr(2,8,223); // Different LCD displays have different
// char code for degree
Lcd_Chr(2,9,'C'); // Display "C" for Celsius
ADC_Init(); // Initialize ADC
do{
temp_res = ADC_Read(0);
temp= (temp_res) * (quanta);
FloatToStr(temp, txt); // Convert temperature to string
Lcd_Out( 2, 3 , txt);
Delay_Ms(1000);
} while(1);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?