0

I was recently asked for a college project with a temperature sensor. It was easy for simulating it on proteus and everything was alright. Then I tried to make it hardware but nothing is happening. The lcd works but no data actually appears on my lcd although the lcd is working fine with my arduino.

I'm using a 4 MHz Crystal oscillator with 2 X 22pf capcitors connected with 12 and 13 pins of atmega16.

Here's my code:

sbit LCD_RS at PORTC2_bit;
sbit LCD_EN at PORTD6_bit;
sbit LCD_D4 at PORTC4_bit;
sbit LCD_D5 at PORTC5_bit;
sbit LCD_D6 at PORTC6_bit;
sbit LCD_D7 at PORTC7_bit;

sbit LCD_RS_Direction at DDC2_bit;
sbit LCD_EN_Direction at DDD6_bit;
sbit LCD_D4_Direction at DDC4_bit; 
sbit LCD_D5_Direction at DDC5_bit;
sbit LCD_D6_Direction at DDC6_bit;
sbit LCD_D7_Direction at DDC7_bit;
const unsigned short VREF = 5.00;

unsigned int temp_res = 0; 
float temp;
char txt[15];

void main() {
    DDA7_bit = 0;                       // Configure PA7 pin as input

    ADC_Init();                        // Initialize ADC

    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

    temp_res = 0;
    do {
        temp_res = ADC_Get_Sample(7);     // Get 10-bit results of AD conversion
        temp = (temp_res * VREF)/10.240;  // Calculate temperature in Celsius
                                          //  change Vref constant according
                                          //  to the power supply voltage
        FloatToStr(temp, txt);            // Convert temperature to string
        txt[4] = 0;
        Lcd_Out(2,3,txt);                 // Write string in second row
        Delay_ms(1000);
    } while(1);
}
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95
  • What do you mean by "No data appeared on my LCD"? That's like the classic "it didn't work". Did it show "Temperature :"? If so, then what? – Weather Vane Mar 13 '15 at 19:28
  • what was the actual value read from ADC_Get_Sample(7)? what was the actual value calculated into temp? What was the actual value/string in txt? This would be a very good time to make use of a debugger – user3629249 Mar 13 '15 at 20:00
  • @WeatherVane the backlight is working and when i connect resistance at vee to control the contrast i see pixels also but i mean with no data nothing appears on the lcd although i tried to write the basic code of hello world but i also got nothing – Muhammed Ashraf Mar 13 '15 at 20:11
  • @user3629249 this is not the point i have also tried the examples code which came with the mikroc program like hello world but i got nothing ! – Muhammed Ashraf Mar 13 '15 at 20:15
  • Then start from basics. Don't attempt to measure the ADC until you can show "Hello World". Step by step. Is there an LED attached which you can toggle to show processor activity? You *will* need one! In the embedded world, "Hello World!" is a winking LED. Then while you bootstrap the output functions, the LED (or even a set of 8) will be your friend. – Weather Vane Mar 13 '15 at 20:20
  • okay i will try this but i don't know what this is keep happening .. i had made the circuit on proteus and everything well :( and thanks for you response :) – Muhammed Ashraf Mar 13 '15 at 20:48
  • No header files included in the your code is at least one problem! – Brian Sidebotham Mar 13 '15 at 23:31

0 Answers0