Introduction: Create Yourself a Message Flasher With ATMEGA128
Guys,
I wanna share my experiment on creating a message flasher with
ATMEGA128 and LCD 16x2,
It can be done on your weekend....
I wanna share my experiment on creating a message flasher with
ATMEGA128 and LCD 16x2,
It can be done on your weekend....
Step 1: Prepare the Components
I prepare all the components below,
The most importants are
ATMEGA128 TQFP 64 and LCD 16x2
Another one,
1 trimpot 1K or a 1K resistor connected to VEE on LCD 16x2 and into GND.
And this is the rest ,please have a look on the screenshot.:
The most importants are
ATMEGA128 TQFP 64 and LCD 16x2
Another one,
1 trimpot 1K or a 1K resistor connected to VEE on LCD 16x2 and into GND.
And this is the rest ,please have a look on the screenshot.:
Step 2: The Schematic
Here's the schematic,
I separate them, because I can not put one screen on one time screenshot...
I assume, you guys have the ability on drawing the PCB since I don't include the PCB drawing here.
Next step is creating the code and compile it...
I separate them, because I can not put one screen on one time screenshot...
I assume, you guys have the ability on drawing the PCB since I don't include the PCB drawing here.
Next step is creating the code and compile it...
Step 3: The Code and Uploading to Your Board
In this step,
We create the code for this experiment,
I used AVR Studio for it and uploaded with USBASP, see the photo
complete code :
#include <avr/io.h>
#include <util/delay.h>
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0 PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
uint8_t b1:1;
uint8_t b2:1;
uint8_t b3:1;
uint8_t b4:1;
uint8_t b5:1;
uint8_t b6:1;
uint8_t b7:1; } bits;
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
//Mention Clock frequency here
#define _XTAL_FREQ 8000000
#define lcd_data_pin PORTA
#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
void lcd_init(){
lcd_cmd(0x30);
_delay_ms(10);
lcd_cmd(0x38);
_delay_ms(10);
lcd_cmd(0x0F);
_delay_ms(10);
lcd_cmd(0x80);
_delay_ms(10);
}
void lcd_data(unsigned char data1)
{
lcd_data_pin = data1;// & 0x0F;
en=1;
rs=1;
rw=0;
_delay_ms(10);
en=0;
}
void lcd_cmd(unsigned char cmd){
lcd_data_pin = cmd ;
en=1;
rs=0;
rw=0;
_delay_ms(10);
en=0;
}
void lcd_string(unsigned char *str){
while(*str){
lcd_data(*str++);
}
}
int main(){
DDR_D.b0 = 1;
DDR_D.b1 = 1;
DDR_D.b2 = 1;
DDRA = 0xFF;
lcd_init();
while(1){
_delay_ms (10);
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_cmd(0xC0);//goto second row
_delay_ms (10);
lcd_cmd(0x01); //Clear display
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Message");
lcd_cmd(0xC0);//goto second row
lcd_string("Flasher");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("With ATMEGA128");
lcd_cmd(0xC0);//goto second row
lcd_string("By arick");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Published on");
lcd_cmd(0xC0);//goto second row
lcd_string("Instructable.com");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Made in");
lcd_cmd(0xC0);//goto second row
lcd_string("AUSTRALIA");
_delay_ms(1000);
}
return (0);
}
We create the code for this experiment,
I used AVR Studio for it and uploaded with USBASP, see the photo
complete code :
#include <avr/io.h>
#include <util/delay.h>
// structure to allow bit field operations, name conversions: PORTA.0 -> PORT_A.b0 PORTB.7 -> PORT_B.b7
typedef struct{ uint8_t b0:1;
uint8_t b1:1;
uint8_t b2:1;
uint8_t b3:1;
uint8_t b4:1;
uint8_t b5:1;
uint8_t b6:1;
uint8_t b7:1; } bits;
// define all the ports of your microcontroller, add more ports depending on the available mcu ports
#define PORT_D (* (volatile bits *) &PORTD)
#define PIN_D (* (volatile bits *) &PIND)
#define DDR_D (* (volatile bits *) &DDRD)
#define PORT_G (* (volatile bits *) &PORTG)
#define PIN_G (* (volatile bits *) &PING)
#define DDR_G (* (volatile bits *) &DDRG)
//Mention Clock frequency here
#define _XTAL_FREQ 8000000
#define lcd_data_pin PORTA
#define en PORT_D.b0
#define rs PORT_D.b1
#define rw PORT_D.b2
void lcd_init();
void lcd_data(unsigned char data1);
void lcd_cmd(unsigned char cmd);
void lcd_control(unsigned char cmdordata);
void lcd_string(unsigned char *str);
void lcd_init(){
lcd_cmd(0x30);
_delay_ms(10);
lcd_cmd(0x38);
_delay_ms(10);
lcd_cmd(0x0F);
_delay_ms(10);
lcd_cmd(0x80);
_delay_ms(10);
}
void lcd_data(unsigned char data1)
{
lcd_data_pin = data1;// & 0x0F;
en=1;
rs=1;
rw=0;
_delay_ms(10);
en=0;
}
void lcd_cmd(unsigned char cmd){
lcd_data_pin = cmd ;
en=1;
rs=0;
rw=0;
_delay_ms(10);
en=0;
}
void lcd_string(unsigned char *str){
while(*str){
lcd_data(*str++);
}
}
int main(){
DDR_D.b0 = 1;
DDR_D.b1 = 1;
DDR_D.b2 = 1;
DDRA = 0xFF;
lcd_init();
while(1){
_delay_ms (10);
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_cmd(0xC0);//goto second row
_delay_ms (10);
lcd_cmd(0x01); //Clear display
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Message");
lcd_cmd(0xC0);//goto second row
lcd_string("Flasher");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("With ATMEGA128");
lcd_cmd(0xC0);//goto second row
lcd_string("By arick");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Published on");
lcd_cmd(0xC0);//goto second row
lcd_string("Instructable.com");
_delay_ms(1000);
//next screen
lcd_cmd(0x80);//put the cursor into the first row
_delay_ms (10);
lcd_cmd(0x01);//Clear display
_delay_ms (10);
lcd_string("Made in");
lcd_cmd(0xC0);//goto second row
lcd_string("AUSTRALIA");
_delay_ms(1000);
}
return (0);
}
Step 4: Test It and Enjoy Your Message Flasher ==> Video ;)
Test it and enjoy your message flasher ==> Video ;)