#include <avr/io.h>
#include <util/delay.h>
// Define the bits in the port
typedef struct
{
unsigned char bit0 : 1,
bit1 : 1,
bit2 : 1,
bit3 : 1,
bit4 : 1,
bit5 : 1,
bit6 : 1,
bit7 : 1;
} bit_field;
// Define macro to get the value of each bit
#define GET_BIT(port) (*(volatile bit_field *) (_SFR_ADDR(port)))
// Define functions for each bit of the I/O ports in the program
#define rs GET_BIT(PORTC).bit0
#define rw GET_BIT(PORTC).bit1
#define en GET_BIT(PORTC).bit2
#define data_port PORTD
void test(unsigned char data1);
void test(unsigned char data1)
{
data_port = data1;
en = 1;
_delay_ms(50);
rs = 0;
_delay_ms(50);
rw = 0;
_delay_ms(80);
en = 0;
}
int main (void)
{
DDRC = 0xFF;
DDRD = 0xFF;
while(1)
{
PORTD = 0x38;
_delay_ms(50);
PORTD = 0x01;
_delay_ms(50);
/*
test(0x38);
_delay_ms(50);
test(0x01);
*/
}
}