1
votes

I found this code somewhere for showing something on LCD via AVR:

#include <stdio.h>
#include <mega16.h>
#include <util/delay.h>
#include <lcd.h>

#define xtal 4000000

#asm
 .equ __lcd_port=0x1B ;PORTA
#endasm

void main(void)
{
    char buffer[10];
    unsigned char w;
    PORTB=0xFF;
    DDRB=0x00;
    lcd_init(16);
    lcd_clear();
    while (1)
    {
        w = ~PINB;
        if(w!=0x00)
        {
            lcd_clear();
            lcd_gotoxy(0,0);
            sprintf(buffer,"Number=%d",w);
            lcd_puts(buffer);
            delay_ms(100);
        }
        else
        {
            lcd_clear();
            lcd_putsf("Number=0");
            delay_ms(100);
        }
    }
}

This code does not run due to so many problems (Messages by codeblock):

||=== Build: Debug in avr (compiler: GNU GCC Compiler for AVR) ===|
main.c|2|error: mega16.h: No such file or directory|
main.c|4|error: lcd.h: No such file or directory|
main.c|8|error: invalid preprocessing directive #asm|
main.c|9|error: expected identifier or '(' before '.' token|
main.c|10|error: invalid preprocessing directive #endasm|
main.c|12|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Where should I find mega16.h and should I install anything to have access to lcd.h ?

This code looks strange.

1
Where did you find this code? It looks like it's for an entirely different toolchain. - user149341
That's definitely not AVR-GCC code. - Ignacio Vazquez-Abrams
@IgnacioVazquez-Abrams that is what I am thinking about. I got is from a pdf book. I dont know how to attach it here. - bahraman
Well, stop using it. Obviously you don't have the Codevision compiler. - Ignacio Vazquez-Abrams

1 Answers

0
votes

You can probably find them on Atmel's website in the AVR programming section. You should probably download their programming tools and manuals to being with.