ANTI_HACKER
Member level 3
- Joined
- Sep 1, 2012
- Messages
- 56
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,722
#include <mega16.h>
#include <delay.h>
#define F_CPU 1000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16))) - 1)
#define rs PORTD.2 // defining rs pin to be PORTC.O
#define rw PORTD.3 //defining rs pin to be PORTC.1
#define en PORTD.4 //defining en pin to be PORCT.2
unsigned char data,message_no,;
unsigned char RFID[]="RFID TAG # is :";
void init_USART(void)
{
UCSRA = 0x00; //control register initialization
UCSRB = 0x98; //enable transmitter and Rx and rx interrupt
UCSRC = 0x86; //async, no parity, 1 stop bit,
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register
}
void lcd_cmd(char ch) // a function used to send commands to lcd
{
rs=0; //setting rs pin to zero (sending a command)
rw=0; //setting rw pin to zero (to write to registers)
PORTA=ch; // sending character on the port
en=1; // setting enable pin
delay_ms(2); //wait to make sure that the command is written successfully
en=0; // clearing enable pin
}
void lcd_data(char ch) // a function used to send data to lcd
{
count++;
rs=1; //setting rs pin to one (sending data)
rw=0; //setting rw pin to zero (to write to registers)
PORTA = ch; // sending character on the port
en=1; // setting enable pin
delay_ms(2); //wait to make sure that the command is written successfully
en=0; // clearing enable pin
}
void init_lcd() // a function to initialize LCD
{
lcd_cmd(0x38); // configuring LCD for a two line display
lcd_cmd(0x0E); //Turning Display and cursor ON
lcd_cmd(0x01); //Clear Screen Display
lcd_cmd(0x06); //Increment Cursor
lcd_cmd(0x0C);
}
void USART_Rx()
{
while((UCSRA & 0x80)==0x00); //wait for RXC flag
data = UDR;
}
void USART_Tx(char DATA)
{
while((UCSRA & 0x20)==0x00); //wait for UDRE flag
UDR = DATA; //load data to UDR for transmission
}
interrupt[12] void USART_RX_INTERRUPT()
{
data = UDR;
lcd_data(data);
}
void main()
{
DDRA=0XFF;
init_lcd(); //initializing LCD
init_USART();
#asm("SEI");
i=0;
while(RFID[i] != '\0')
{
lcd_data(RFID[i]);
i++;
}
lcd_cmd(0xC0);
/*
while(1)
{
USART_Rx();
lcd_data(data);
}
*/
while(1); // Receiving by interrupts
}
void main()
{
DDRA=0XFF;
DDRD.2=1;
DDRD.3=1;
DDRD.4=1;
init_lcd(); //initializing LCD
init_USART();
while(1)
{
USART_Rx();
lcd_data(data);
}
}
#define F_CPU 1000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 8))) - 1)
#define F_CPU 1000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16))) - 1)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?