Soy nuevo en sistemas embebidos Escribo este código y traté de compilarlo en "AVR Studio" pero tengo un error y no puedo corregirlo el error es: "declaración o declaración esperada al final de la entrada" y consulte la última línea del código
ayúdame a encontrar la ubicación de este error
EL CÓDIGO:
/*
* AVRGCC1.c
*
* Created: 2/8/2012 1:11:07 PM
* Author: heha
*/
#define nibble 0 //determine nibble mode if 1 or 8-bit mode if 0
DDRD = 0XFF;
DDRB = 0X07;
#define portfor3pins PORTB
//define EN at PORTB pin no. 0
//define RS at PORTB pin no. 1
//define RW at PORTB pin no. 2
#define port PORTD
//LCD's DB pins deal with port D
//in 8-bit mode connect DB0 to p0 and DB1 to p1 and so on until DB7 to p7
//in nibble mode connect DB4 to p4 and DB5 to p5 and DB6 to p6 and DB7 to p7
#include <avr/io.h>
#include <stdint.h>
#include <string.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
void RS(unsigned char i);
void EN(unsigned char i);
void RW(unsigned char i);
void initialization();
void clearscreen();
void movecursortohome();
void setcursorstate(unsigned char isblinking, unsigned char ison);
void setcursorblink();
void setcursornoblink();
void setcursoron();
void setcursoroff();
void writecharatpos(unsigned char row, unsigned char col, char ch);
void setcursorpos(unsigned char row, unsigned char col);
void writestringatpos(unsigned char row, unsigned char col, const char data[]);
void RS(unsigned char i) {
if (i == 1)
portfor3pins |= 0X02;
else
portfor3pins &= 0XFD;
}
void EN(unsigned char i) {
if (i == 1)
portfor3pins |= 0X01;
else
portfor3pins &= 0XFE;
}
void RW(unsigned char i) {
if (i == 1)
portfor3pins |= 0X04;
else
portfor3pins &= 0XFB;
}
void initialization() {
_delay_ms(3); //3
EN(1);
if (nibble) {
port = 0X30;
_delay_ms(1);
port = 0x00;
_delay_ms(50);
port = 0x30;
_delay_ms(1);
port = 0x00;
_delay_ms(10);
port = 0x30;
_delay_ms(1);
port = 0x00;
_delay_ms(1);
port = 0x20;
_delay_ms(1);
port = 0x00;
_delay_ms(50);
RS(0);
RW(0);
port = 0X20; //DL=0
_delay_ms(1);
port = 0X80; //N=1,F=0
_delay_ms(1);
port = 0X00;
_delay_ms(1);
port = 0X80; //D=C=B=0
_delay_ms(1);
port = 0X00;
_delay_ms(1);
port = 0XF0;
_delay_ms(1);
port = 0X00;
_delay_ms(1);
port = 0X60; //S=0,I/D=1
_delay_ms(1);
port = 0X00;
_delay_ms(1);
port = 0X10;
_delay_ms(50);
} else {
port = 0x30;
_delay_ms(50);
port = 0x30;
_delay_ms(10);
port = 0x30;
_delay_ms(1);
port = 0x30;
_delay_ms(50);
RS(0);
RW(0);
port = 0X38; //DL=1,N=1,F=0
_delay_ms(1);
port = 0X08;//D=C=B=0
_delay_ms(1);
port = 0X0F;
_delay_ms(1);
port = 0X06;//S=0,I/D=1
_delay_ms(1);
port = 0X01;
_delay_ms(50);
}
}
void clearscreen() {
EN(1);
RS(0);
RW(0);
if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0X10;
} else
port = 0X01;
_delay_ms(1);
}
void movecursortohome() {
EN(1);
RS(0);
RW(0);
if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0X30;
} else
port = 0X03;
_delay_ms(2);
}
void setcursorstate(unsigned char isblinking, unsigned char ison) {
RS(0);
RW(0);
EN(1);
if ((isblinking == 0) && (ison == 0)) {
if (nibble) {
port = 0x00;
_delay_ms(1);
port = 0xC0;
} else
port = 0x0C;
} else if ((isblinking == 1) && (ison == 0)) {
if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0XD0;
} else
port = 0X0D;
} else if ((isblinking == 0) && (ison == 1)) {
if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0XE0;
} else
port = 0X0E;
} else {
if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0XF0;
} else
port = 0X0F;
}
_delay_ms(1);
}
void setcursorblink() {
RS(0);
RW(0);
EN(1);
port &= 0x0f;
_delay_ms(1);
if (!nibble)
port |= 0x09;
else if (nibble)
port |= 0x90;
_delay_ms(1);
}
void setcursornoblink() {
RS(0);
RW(0);
EN(1);
if (!nibble) {
port &= 0X0E;
_delay_ms(1);
port |= 0X08;
} else if (nibble) {
port = 0x00;
_delay_ms(1);
port |= 0x80;
}
_delay_ms(1);
}
void setcursoron() {
RS(0);
RW(0);
EN(1);
port &= 0x0f;
_delay_ms(1);
if (!nibble)
port |= 0X0A;
else if (nibble)
port |= 0XA0;
_delay_ms(1);
}
void setcursoroff() {
RS(0);
RW(0);
EN(1);
if (!nibble) {
port &= 0X0D;
_delay_ms(1);
port |= 0X08;
} else if (nibble) {
port = 0X00;
_delay_ms(1);
port |= 0X80;
}
_delay_ms(1);
}
void writecharatpos(unsigned char row, unsigned char col, char ch)
{
char pos, i, y, z;
RS(0);
RW(0);
EN(1);
if (row == 0) {
pos = 0X80 + col; //in fact I don't use this variable later
movecursortohome();
for (i = 0; i < col; i++) {
if (!nibble) {
port &= 0XFE;
_delay_ms(1);
port |= 0X06;
_delay_ms(1);
port = 0X14;
} else if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0X60;
_delay_ms(1);
port = 0X10;
_delay_ms(1);
port = 0X40;
}
}
} else if (row == 1) {
pos = 0XC0 + col; //in fact I don't use this variable later
if (nibble) {
port = 0XC0;
_delay_ms(1);
port = 0X00;
} else if (!nibble)
port = 0XC0;
for (i = 0; i < col; i++) {
if (!nibble) {
port &= 0XFE;
_delay_ms(1);
port |= 0X06;
_delay_ms(1);
port = 0X14;
}
else if (nibble) {
port = 0X00;
_delay_ms(1);
port = 0X60;
_delay_ms(1);
port = 0X10;
_delay_ms(1);
port = 0X40;
}
}
_delay_ms(1);
RS(1);
if (!nibble)
port = ch;
else {
z = ch;
y = ch;
for (i = 0; i <3;i++)
z << 1;
port = y;
_delay_ms(1);
port = z;
}
_delay_ms(1);
}
void setcursorpos(unsigned char row, unsigned char col) {
char i;
RS(0);
RW(0);
EN(1);
if (row == 0)
movecursortohome();
else if (row == 1) {
if (nibble) {
port = 0XC0;
_delay_ms(1);
port = 0X00;
} else
port = 0XC0;
}
_delay_ms(1);
for (i = 0; i < col; i++) {
if (!nibble)
port = 0X14;
else {
port = 0X10;
_delay_ms(1);
port = 0x40;
}
}
}
void writestringatpos(unsigned char row, unsigned char col,
const char data[]) {
char length, i, z, y;
if (row == 0)
movecursortohome();
else if (row == 1) {
if (nibble) {
port = 0XC0;
_delay_ms(1);
port = 0X00;
} else
port = 0XC0;
}
_delay_ms(1);
for (i = 0; i < col; i++) {
if (!nibble)
port = 0X14;
else {
port = 0X10;
_delay_ms(1);
port = 0X40;
}
}
_delay_ms(1);
length = strlen(data);
RS(1);
for (i = 1; i <= length; i++) {
if (!nibble) {
port = data[i];
_delay_ms(1);
port &= 0XFE;
_delay_ms(1);
port |= 0X06;
_delay_ms(1);
port = 0X14;
} else {
z = data[i];
y = data[i];
for (i = 0; i <3;i++)
z << 1;
port = y;
_delay_ms(1);
port = z;
_delay_ms(1);
port = 0x00;
_delay_ms(1);
port = 0x60;
_delay_ms(1);
port = 0x10;
_delay_ms(1);
port = 0x40;
}
}
_delay_ms(1);
}
int main(void) {
initialization();
/*while(1)
{
}*/
}