Leo Linuxhnrainll.blog.chinaunix.net
hnrainll
全部博文(354)
2010年(300)
2009年(54)
大鬼不动
叶绍琛
路沐堇
HoariNes
快乐的猪
6551130
zjt_pond
K__奕__
cynthia
格伯纳
Bsolar
葫芦娃的
分类: 嵌入式
2010-08-12 16:33:19
#include <avr/io.h> #include <util/delay.h> #include "lcd1602.h" #define Set_Lcd1602_RS Contrl_Port |= (1 << RS) #define Clr_Lcd1602_RS Contrl_Port &= ~(1 << RS) #define Set_Lcd1602_RW Contrl_Port |= (1 << RW) #define Clr_Lcd1602_RW Contrl_Port &= ~(1 << RW) #define Set_Lcd1602_EN Contrl_Port |= (1 << EN) #define Clr_Lcd1602_EN Contrl_Port &= ~(1 << EN) void LCD1602BusyCheck(void) { uint8_t i = 254; Data_DDR = 0x00; Clr_Lcd1602_RS; Set_Lcd1602_RW; Set_Lcd1602_EN; _delay_us(5); while((i--) && (Data_PIN & 0x80)); Data_DDR = 0xff; _delay_us(5); Clr_Lcd1602_EN; _delay_us(5); } void LCD1602WriteOperation(uint8_t Data,uint8_t ComOrData) { LCD1602BusyCheck(); if(0 == ComOrData) Clr_Lcd1602_RS; else if(1 == ComOrData) Set_Lcd1602_RS; Clr_Lcd1602_RW; Set_Lcd1602_EN; _delay_us(5); Data_Port = Data; _delay_us(5); Clr_Lcd1602_EN; _delay_us(100); } void LCD1602Init(void) { LCD1602WriteOperation(0x38,0); _delay_ms(15); LCD1602WriteOperation(0x38,0); _delay_ms(5); LCD1602WriteOperation(0x38,0); _delay_ms(5); LCD1602WriteOperation(0x38,0); _delay_ms(5); LCD1602WriteOperation(0x0c,0); _delay_ms(1); LCD1602WriteOperation(0x06,0); _delay_ms(1); LCD1602WriteOperation(0x01,0); _delay_ms(1); } void LCD1602MoveToPosition(uint8_t ucx,uint8_t ucy) { if(0 == ucx) { LCD1602WriteOperation(0x80 + ucy,0); } if(1 == ucx) { LCD1602WriteOperation(0xC0 + ucy,0); } } void LCD1602PrintString(uint8_t const * str) { while(*str != '\0') { LCD1602WriteOperation(*str,1); str++; } }
#ifndef __LCD1602_H__ #define __LCD1602_H__ #define RS PA4 #define RW PA5 #define EN PA6 #define Contrl_Port PORTA #define Contrl_DDR DDRA #define Contrl_PIN PINA #define Data_Port PORTB #define Data_DDR DDRB #define Data_PIN PINB //void LCD1602BusyCheck(void); void LCD1602WriteOperation(uint8_t Data,uint8_t ComOrData); void LCD1602Init(void); void LCD1602MoveToPosition(uint8_t ucx,uint8_t ucy); void LCD1602PrintString(uint8_t const * str); #endif
#include <avr/io.h> #include <util/delay.h> #include "lcd1602" uint8_t ucString1[] = {"This a LCD demo"}; uint8_t ucString2[] = {""}; uint8_t ucString3[] = {" KEEP MOVING! "}; uint8_t ucString4[] = {"BY: kevin chin"}; int main(void) { PORTA = 0xff; DDRA = 0xff; PORTB = 0xff; DDRB = 0xff; LCD1602Init(); while(1) { LCD1602MoveToPosition(0,0); LCD1602PrintString(ucString1); LCD1602MoveToPosition(1,0); LCD1602PrintString(ucString2); _delay_ms(5000); //延时5毫秒 LCD1602MoveToPosition(0,0); LCD1602PrintString(ucString3); LCD1602MoveToPosition(1,0); //延时5毫秒 LCD1602PrintString(ucString4); _delay_ms(5000); } }
上一篇:基于AT89S52和FAT16的SD卡读写系统设计.doc
下一篇:什么是TFT颜色?
登录 注册