Avatar billede vilvide2 Nybegynder
17. december 2007 - 13:03 Der er 2 kommentarer

AVR microchip

Jeg kan ikke compile en lcd opsætning til mega8 med avr studio

jeg forstår det ikke. hjælp mig

lcd fil endenunder og complier error øverst.


avr-gcc.exe  -mmcu=atmega8 -Wall -gdwarf-2 -O0 -MD -MP -MT avrbeglcd.o -MF dep/avrbeglcd.o.d  -c  ../avrbeglcd.c
In file included from ../avrbeglcd.c:2:
C:/WinAVR/bin/../lib/gcc/avr/3.4.3/../../../../avr/include/avr/delay.h:121:3: warning: #warning "F_CPU not defined for <avr/delay.h>"
../avrbeglcd.c: In function `LCD_wait':

warning er ok, men error nedenunder????

../avrbeglcd.c:62: error: parse error before '}' token
make: *** [avrbeglcd.o] Error 1
Build failed with 1 errors and 1 warnings...




#include <avr/io.h>
#include <avr/delay.h>
#define LCD_RS 0
#define LCD_RW 1
#define LCD_E 2

//LCD_putchar writes a character to the LCD at the current address,
//no busy flag check is done before or after
//the character is written!
//usage: LCD_putchar('A'); or LCD_putchar(0x55);
void LCD_putchar(char data)
{
    //PortD is output
    DDRD = 0xFF;
    //put data on bus
    PORTD = data;
    //RW low, E low
    PORTC &= ~((1<<LCD_RW)|(1<<LCD_E));
    //RS high, strobe E
    PORTC |= ((1<<LCD_RS)|(1<<LCD_E));
    //the number of nops required varies with your clock frequency, try it out!
    asm volatile ("nop");
    asm volatile ("nop");
    asm volatile ("nop");
    asm volatile ("nop");
    //RS low again, E low (belongs to strobe)
    PORTC &= ~((1<<LCD_RS)|(1<<LCD_E));
    //release bus
    DDRD = 0;
}

//LCD_getaddress reads the address counter and busy flag. For the address only,
//mask off bit7 of the return value.
char LCD_getaddr(void)
{
    //make var for the return value
    char address;
    //PortD is input
    DDRD = 0;
    //RW high, strobe enable
    PORTC |= ((1<<LCD_RW)|(1<<LCD_E));
    asm volatile ("nop");
    asm volatile ("nop");
    //while E is high, get data from LCD
    address = PIND;
    //reset RW to low, E low (for strobe)
    PORTC &= ~((1<<LCD_RW)|(1<<LCD_E));
    //return address and busy flag
    return address;
}

//LCD_wait reads the address counter (which contains the busy flag) and loops until
//the busy flag is cleared.


void LCD_wait(void)
{
    //get address and busy flag
    //and loop until busy flag cleared

    while ((LCD_getaddr() & 0x80) == 0x80)
}

//LCD_command works EXACTLY like LCD_putchar, but takes RS low for accessing the command reg
//see LCD_putchar for details on the code
void LCD_command(char command)
{
    DDRD = 0xFF;
    PORTD = command;
    PORTC &= ~((1<<LCD_RS)|(1<<LCD_RW)|(1<<LCD_E));
    PORTC |= (1<<LCD_E);
    asm volatile ("nop");
    asm volatile ("nop");
    asm volatile ("nop");
    asm volatile ("nop");
    PORTC &= ~(1<<LCD_E);
    DDRD = 0;
}

/*LCD_init initialises the LCD with the following paramters:
8 bit mode, 5*7 font, 2 lines (also for 4 lines)
auto-inc cursor after write and read
cursor and didsplay on, cursor blinking.
*/
void LCD_init(void)
{
    //setup the LCD control signals on PortC
    DDRC |= ((1<<LCD_RS)|(1<<LCD_RW)|(1<<LCD_E));
    PORTC = 0x00;
    //if called right after power-up, we'll have to wait a bit (fine-tune for faster execution)
    _delay_loop_2(0xFFFF);
    //tell the LCD that it's used in 8-bit mode 3 times, each with a delay inbetween.
    LCD_command(0x30);
    _delay_loop_2(0xFFFF);
    LCD_command(0x30);
    _delay_loop_2(0xFFFF);
    LCD_command(0x30);
    _delay_loop_2(0xFFFF);
    //now: 8 bit interface, 5*7 font, 2 lines.
    LCD_command(0x38);
    //wait until command finished
    LCD_wait();
    //display on, cursor on (blinking)
    LCD_command(0x0F);
    LCD_wait();
    //now clear the display, cursor home
    LCD_command(0x01);
    LCD_wait();
    //cursor auto-inc
    LCD_command(0x06);
}

//now it's time for a simple function for showing strings on the LCD. It uses the low-level
//functions above. usage example: LCD_write("Hello World!");
void LCD_write(char* dstring)
{
    //is the character pointed at by dstring a zero? If not, write character to LCD
    while(*dstring)
    {
        //if the LCD is bus, let it finish the current operation
        LCD_wait();
        //the write the character from dstring to the LCD, then post-inc the dstring is pointing at.
        LCD_putchar(*dstring++);
    }
}
Avatar billede driis Nybegynder
17. december 2007 - 19:17 #1
Det ville være nemmere hvis du markerede linie 62 for os så vi ikke selv skal gætte (eller endnu værre, tælle manuelt) ;-).

Men der mangler i hvert fald et semikolon til at afslutte while-løkken her:

void LCD_wait(void)
{
    //get address and busy flag
    //and loop until busy flag cleared

    while ((LCD_getaddr() & 0x80) == 0x80)
}
Avatar billede vilvide2 Nybegynder
18. december 2007 - 10:15 #2
super duper

kender du til nogen andre eks??????
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester