jayanth.devarayanadurga
Banned
- Joined
- Dec 4, 2012
- Messages
- 4,280
- Helped
- 822
- Reputation
- 1,654
- Reaction score
- 791
- Trophy points
- 1,393
- Location
- Bangalore, India
- Activity points
- 0
Why I am getting errors when Compiling this Code?
Atmel Studio 6.1 Code. ATMega128, 8 MHz
Project files + Proteus file attached.
Atmel Studio 6.1 Code. ATMega128, 8 MHz
Project files + Proteus file attached.
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 /* * lcd4bit.c * * Created: 5/7/2013 9:09:11 AM * Author: Jayanth Devarayanadurga */ #include <avr/io.h> #include <util/delay.h> //Mention Clock frequency here #define _XTAL_FREQ 8000000 //Define CPU Frequency //This must be defined, if __delay_ms() or //__delay_us() functions are used in the code #define _XTAL_FREQ 8000000 #define LCD_RS PINA0 #define LCD_EN PINA5 #define LCD_D4 PINB4 #define LCD_D5 PINB6 #define LCD_D6 PINC7 #define LCD_D7 PIND4 #define _LCD_FIRST_ROW 0x80 //Move cursor to the 1st row #define _LCD_SECOND_ROW 0xC0 //Move cursor to the 2nd row #define _LCD_THIRD_ROW 0x94 //Move cursor to the 3rd row #define _LCD_FOURTH_ROW 0xD4 //Move cursor to the 4th row #define _LCD_CLEAR 0x01 //Clear display #define _LCD_RETURN_HOME 0x02 //Return cursor to home position, returns a shifted display to //its original position. Display data RAM is unaffected. #define _LCD_CURSOR_OFF 0x0C //Turn off cursor #define _LCD_UNDERLINE_ON 0x0E //Underline cursor on #define _LCD_BLINK_CURSOR_ON 0x0F //Blink cursor on #define _LCD_MOVE_CURSOR_LEFT 0x10 //Move cursor left without changing display data RAM #define _LCD_MOVE_CURSOR_RIGHT 0x14 //Move cursor right without changing display data RAM #define _LCD_TURN_ON 0x0C //Turn Lcd display on #define _LCD_TURN_OFF 0x08 //Turn Lcd display off #define _LCD_SHIFT_LEFT 0x18 //Shift display left without changing display data RAM #define _LCD_SHIFT_RIGHT 0x1E //Shift display right without changing display data RAM // Constants #define EN_Delay 500 // Give a pulse on E pin // so that LCD can latch the // data from data bus #define LCD_STROBE {LCD_EN = 1; _delay_us(EN_Delay); LCD_EN = 0; _delay_us(EN_Delay);}; //Function Prototypes void LCD_Cmd(unsigned char Command); void LCD_Ch(unsigned int row, unsigned int col, char LCDChar); void LCD_Init(); void LCD_Out(unsigned int row, unsigned int col, const char *str); void LCD_Cmd(unsigned char Command) { LCD_RS = 0; // It is a command LCD_D4 = (Command & 0x10)?1:0; LCD_D5 = (Command & 0x20)?1:0; LCD_D6 = (Command & 0x40)?1:0; LCD_D7 = (Command & 0x80)?1:0; LCD_STROBE; LCD_D4 = (Command & 0x01)?1:0; LCD_D5 = (Command & 0x02)?1:0; LCD_D6 = (Command & 0x04)?1:0; LCD_D7 = (Command & 0x08)?1:0; LCD_STROBE; if(Command == 0x01) _delay_ms(2); // Delay for cursor to return at zero position } void LCD_Ch(unsigned int row, unsigned int col, char LCDChar) { switch(row){ case 1: LCD_Cmd(0x80 + col-1); break; case 2: LCD_Cmd(0xC0 + col-1); break; case 3: LCD_Cmd(0x94 + col-1); break; case 4: LCD_Cmd(0xD4 + col-1); break; } LCD_RS = 1; // It is data LCD_D4 = (LCDChar & 0x10)?1:0; LCD_D5 = (LCDChar & 0x20)?1:0; LCD_D6 = (LCDChar & 0x40)?1:0; LCD_D7 = (LCDChar & 0x80)?1:0; LCD_STROBE; LCD_D4 = (LCDChar & 0x01)?1:0; LCD_D5 = (LCDChar & 0x02)?1:0; LCD_D6 = (LCDChar & 0x04)?1:0; LCD_D7 = (LCDChar & 0x08)?1:0; LCD_EN = 1; LCD_STROBE; } void LCD_Init() { LCD_RS = 0; LCD_EN = 0; LCD_D4 = 0; LCD_D5 = 0; LCD_D6 = 0; LCD_D7 = 0; ///////////////// Reset process from datasheet ////////////// _delay_ms(30); //Make Data pins zero LCD_D4 = 0; LCD_D5 = 0; LCD_D6 = 0; LCD_D7 = 0; //Write 0x3 value on data bus LCD_D4 = 1; LCD_D5 = 1; LCD_D6 = 0; LCD_D7 = 0; LCD_STROBE; _delay_ms(6); //Make Data pins zero LCD_D4 = 0; LCD_D5 = 0; LCD_D6 = 0; LCD_D7 = 0; //Write 0x3 value on data bus LCD_D4 = 1; LCD_D5 = 1; LCD_D6 = 0; LCD_D7 = 0; LCD_STROBE; _delay_ms(3); //Make Data pins zero LCD_D4 = 0; LCD_D5 = 0; LCD_D6 = 0; LCD_D7 = 0; //Write 0x3 value on data bus LCD_D4 = 1; LCD_D5 = 1; LCD_D6 = 0; LCD_D7 = 0; LCD_STROBE; _delay_ms(2); //Make Data pins zero LCD_D4 = 0; LCD_D5 = 0; LCD_D6 = 0; LCD_D7 = 0; //Write 0x2 value on data bus LCD_D4 = 0; LCD_D5 = 1; LCD_D6 = 0; LCD_D7 = 0; LCD_STROBE; _delay_ms(2); /////////////// Reset Process End //////////////// LCD_Cmd(0x28); //function set LCD_Cmd(0x0C); //display on,cursor off,blink off LCD_Cmd(0x06); //entry mode, set increment } void LCD_Out(unsigned int row, unsigned int col, const char *str) { while(*str) LCD_Ch(row,col++,*str++); // print first character on LCD row = 1; col = 1; } int main(void){ DDRA = 0xFF; DDRB = 0xFF; DDRC = 0xFF; DDRD = 0xFF; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; PORTD = 0x00; LCD_Init(); LCD_Cmd(_LCD_CLEAR); LCD_Cmd(_LCD_CURSOR_OFF); LCD_Out(1,1,"PIC18F458"); LCD_Out(2,1,"LCD 4-bit"); LCD_Out(3,1,"20X4"); LCD_Out(4,1,"Working?"); while(1); return (0); }