BASIC4MCU | 질문게시판 | avr 질문입니다.
페이지 정보
작성자 비공개 작성일2018-06-07 10:08 조회6,939회 댓글0건본문
#include <avr/io.h>
//
#define F_CPU 8000000UL
#define outp(x,y) ((y)=(x))
#define inp(x) (x)
#define LCD_RS_SET sbi(PORTD,0)
#define LCD_RS_CLEAR cbi(PORTD,0)
#define LCD_RW_SET sbi(PORTD,1)
#define LCD_RW_CLEAR cbi(PORTD,1)
#define LCD_E_SET sbi(PORTD,2)
#define LCD_E_CLEAR cbi(PORTD,2)
#define LCD_LIGHT_SET sbi(PORTD,3)
#define LCD_LIGHT_CLEAR cbi(PORTD,3)
//
#define sbi(PORTX,bitX)PORTX|=(1<<bitX)
#define cbi(PORTX,bitX)PORTX&=~(1<<bitX)
//
unsigned char display_data1[]=" HANKYONG ";
unsigned char display_data2[]=" HAMHAMHAM ";
//
void delay(unsigned int i){ while(--i); }
//
void lcd_busy(void){
unsigned char busy_data;
busy_data=0; LCD_E_CLEAR; outp(0x00,DDRB);
do{ LCD_RS_CLEAR; LCD_RW_SET; LCD_E_SET; busy_data=inp(PINB); LCD_E_CLEAR; } while(busy_data&0x80);
outp(0xFF,DDRB);
}
//
void lcd_enable(void){ LCD_E_SET; delay(100); LCD_E_CLEAR; }
//
void lcd_func_set(void){ LCD_RW_CLEAR; LCD_RS_CLEAR; outp(0x38,PORTB); lcd_enable(); }
//
void lcd_command(unsigned char lcd_data){
lcd_busy(); delay(1000); LCD_RW_CLEAR; LCD_RS_CLEAR; outp(lcd_data,PORTB); lcd_enable();
}
//
void lcd_init(void){
LCD_E_CLEAR; delay(50000);
lcd_func_set(); delay(10000); lcd_func_set(); delay(1000); lcd_func_set(); delay(1000);
lcd_command(0x38); lcd_command(0x0C); lcd_command(0x01); lcd_command(0x06);
}
//
void lcd_write_char(unsigned char lcd_data){
lcd_busy(); delay(1000); LCD_RW_CLEAR; LCD_RS_SET; outp(lcd_data,PORTB); lcd_enable();
}
//
void lcd_display(void){
unsigned char i;
LCD_LIGHT_SET;
lcd_command(0x02); for(i=0; i<16; i++){ lcd_write_char(display_data1[i]); }
lcd_command(0xC0); for(i=0; i<16; i++){ lcd_write_char(display_data2[i]); }
}
//
int main(void){
unsigned char b=0x01,d=0;
DDRC=0xff;
lcd_init();
while(1){
PORTC=b; delay(100);
if(d==0){
b<<=1;
if(b==0x00){ b=0x80; d=1; }
}
else{
b>>=1;
if(b==0x00){ b=0x01; d=0; } //방향전환
}
//
outp(0xFF,DDRB); outp(0x0F,DDRD); outp(0x00,PORTD);
lcd_display();
}
}
이렇게 실행 시켰더니 lcd랑 led모두 동작하지 않네요..
뭐가 문제일까요?
댓글 0
조회수 6,939등록된 댓글이 없습니다.