

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The program for interfacing an avr microcontroller with an lcd. It includes functions for initializing the lcd, sending data to it, and displaying characters on the screen.
Typology: Study Guides, Projects, Research
1 / 2
This page cannot be seen from the preview
Don't miss anything!


// Project: // Author: // Module description: // ***********************************************************
#include // Most basic include files #include // Add the necessary ones #include // here #include
// Define here the global static variables // // *********************************************************** // Main program // void intz(void) { DDRB=0XFF; // OUTPUT CONFIG PORTB DDRA=0XFF; // OUTPUT CONFIG PORTA // STEP 1 _delay_ms(15); // delay 15 milli-seconds
// STEP 2 PORTA=0X05; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD and r/s=0 for data PORTB=0X30; // WRITE 0X PORTA=0X01; // CLOCK LOW _delay_ms(5); // delay 5 milli
// STEP 3 PORTA=0X05; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD PORTB=0X30; // WRITE 0X PORTA=0X01; // CLOCK LOW _delay_us(160); // delay 160 micro
// STEP 4 PORTA=0X05; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD PORTB=0X30; // WRITE 0X PORTA=0X01; // CLOCK LOW _delay_us(160); // delay 160 micro
// STEP 5 // SET INTERFACE LENGTH PORTA=0X04; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD and r/s=1 for inst PORTB=0X38; // dl=1 for 8bit, n=1 for 2 lines, f=0 for font(5*8) PORTA=0X00; // CLOCK LOW _delay_ms(15); // delay 15 milli-seconds // TURN OFF LCD PORTA=0X04; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD PORTB=0X10; // LCD OFF PORTA=0X00; // CLOCK LOW _delay_ms(15); // delay 15 milli-seconds
_delay_ms(15); // delay 15 milli-seconds // SER CURSOR MOVE DIRECTION PORTA=0X04; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD PORTB=0X00; // NO MOVE ENABLE SHIFTING IS OFF PORTA=0X00; // CLOCK LOW _delay_ms(15); // delay 15 milli-seconds // ENABLE DISPLAY PORTA=0X04; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD PORTB=0X0F; // CURSOR ON, BLINKING ON, DISPLAY ON PORTA=0X00; // CLOCK LOW _delay_ms(15); // delay 15 milli-seconds return; } void data_send(int data) { PORTA=0X05; // CLOCK HIGH AND R/W=0 FOR WRITING TO LCD and r/s=0 for data PORTB=data; // WRITE 0X PORTA=0X01; // CLOCK LOW _delay_ms(5); // delay 5 milli } int main(void) { int data; intz(); // callin intz fucntion data=83; data_send(data); data=65; data_send(data); data=78; data_send(data); data=65; data_send(data);
}