▼▼▼▼▼▼
#include <avr/io.h>
#define F_CPU 1000000
#include <util/delay.h>
#include <stdlib.h>
#define enable 5
#define registerselection 6
void send_a_command(unsigned char command); //명령어전송 메소드
void send_a_character(unsigned char character); //글자전송 메소드
void send_a_string(char *string_of_characters); //문자열전송 메소드
int main(void)
{
DDRA = 0xFF; //LCD의 D0~D7까지 (Output)
DDRB = 0b11111111; //(Output)
PORTB|=(1<<PINB0)|(1<<PINB1); //PORTB레지스터의 PINB0, PIN1포트를 Set
DDRD = 0b11111110; //D0는 RS232포트신호를 위한 입력.
_delay_ms(50);
UCSRB |=(1<<RXEN)|(1<<RXCIE); //UCSRB레지스터의 RXEN, RXCIE를 Set
UCSRC |=(1<<URSEL)|(1<<UCSZ0)|(1<<UCSZ1);
UCSRC &=~(1<<UMSEL); //Setting UMSEL to 0 for asyncronous ()
UBRRH &=~(1<<URSEL); //UBRRH레지스터의 URSEL을 0으로 리셋
UBRRL=6;
char ADMIT [5][4]={{(0x97),(0xa1),(0x90),(0x92)},
{(0x97),(0xa1),(0x90),(0x93)},
{(0x97),(0xa1),(0x90),(0x94)},
{(0x97),(0xa1),(0x90),(0x95)},
{(0x97),(0xa1),(0x90),(0x96)}}; //5Row, 4Column
int16_t COUNTA = 0; //Short
char SHOWA [4];
int i=0;
send_a_command(0x01); //Clear Screen 0x01 = 00000001
_delay_ms(50);
send_a_command(0x38);
_delay_ms(50);
send_a_command(0b00001111);
_delay_ms(50);
char MEM[4];
send_a_string ("RFID NUMBER");
send_a_command(0x80 + 0x40 + 0);
while(1)
{
while(!(UCSRA&(1<<RXC)));
{
}
COUNTA=UDR;
MEM[0]=COUNTA;
itoa(COUNTA,SHOWA,16);
send_a_string(SHOWA);
while(!(UCSRA&(1<<RXC)));
{
}
COUNTA=UDR;
itoa(COUNTA,SHOWA,16);
send_a_string(SHOWA);
MEM[1]=COUNTA;
while(!(UCSRA&(1<<RXC)));
{
}
COUNTA=UDR;
itoa(COUNTA,SHOWA,16);
send_a_string(SHOWA);
MEM[2]=COUNTA;
while(!(UCSRA&(1<<RXC)));
{
}
COUNTA=UDR;
itoa(COUNTA,SHOWA,16);
send_a_string(SHOWA);
MEM[3]=COUNTA;
send_a_string(" ");
send_a_command(0x80 + 0x40 + 0);
UCSRB &=~(1<<RXEN);
for (i=0;i<5;i++)
{
if ((MEM[0]==ADMIT[i][0])&(MEM[1]==ADMIT[i][1])&(MEM[2]==ADMIT[i][2])&(MEM[3]==ADMIT[i][3]))
{
PORTB|=(1<<PINB3);
PORTB&=~(1<<PINB0);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
PORTB|=(1<<PINB0);
PORTB&=~(1<<PINB1);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
_delay_ms(220);
PORTB&=~(1<<PINB3);
PORTB|=(1<<PINB1);
}
}
UCSRB |=(1<<RXEN);
}
}
//▼메소드 선언들
void send_a_command(unsigned char command) //void 메소드명(변수)
{
PORTA = command;
PORTD &= ~ (1<<registerselection);
PORTD |= 1<<enable;
_delay_ms(20);
PORTD &= ~1<<enable;
PORTA = 0;
}
void send_a_character(unsigned char character)
{
PORTA = character;
PORTD |= 1<<registerselection;
PORTD |= 1<<enable;
_delay_ms(20);
PORTD &= ~1<<enable;
PORTA = 0;
}
void send_a_string(char *string_of_characters)
{
while(*string_of_characters > 0)
{
send_a_character(*string_of_characters++);
}
}
▲▲▲▲▲▲▲▲▲▲▲▲