|
用AVR GCC 編寫的1602驅(qū)動程序 為什么總是不顯示,求大神幫忙,謝謝了。
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
#include<avr/iom64.h>
#include <avr/pgmspace.h>//須增加的頭文件,定義長數(shù)據(jù)
#define uint unsigned int
#define uchar unsigned char
uchar s[] = "113456789
uchar s[] = "I like AVR";
// 1602接到 atmega16的端子RS==PC0, RW=PC1,E=PC2
void LCD_Com_Write(uchar comm)
{
PORTC&=~_BV(0);//命令和寫 RS
PORTC&=~_BV(1);//命令和寫RW
PORTC|=_BV(2);//使能有效 E
_delay_ms(10);
PORTA=comm;
PORTC&=~_BV(2);//使能關(guān)閉
}
void LCD_Data_Write(uchar data)
{
PORTC|= _BV(0) ;//數(shù)據(jù)
PORTC&=~_BV(1);//寫
PORTC|=_BV(2);//使能有效
_delay_ms(10);
PORTA=data;
PORTC&=~_BV(2);//使能關(guān)閉
}
void LCD_Init()
{
DDRC=0XFF;
DDRA=0XFF;
_delay_ms(15);
LCD_Com_Write(0x38);//設(shè)置顯示模式
_delay_ms(5);
LCD_Com_Write(0x38);//設(shè)置顯示模式
_delay_ms(5);
LCD_Com_Write(0x38);//設(shè)置顯示模式
_delay_ms(5)
LCD_Com_Write(0x38);//設(shè)置顯示模式
_delay_ms(5);
LCD_Com_Write(0x08);//顯示關(guān)閉
_delay_ms(5);
LCD_Com_Write(0x01);//顯示清屏
_delay_ms(5)
LCD_Com_Write(0x0F);//光標(biāo)和背景設(shè)置
_delay_ms(5);
LCD_Com_Write(0x06);//光標(biāo)設(shè)置,和數(shù)據(jù)地址增減
_delay_ms(5);
}
int main(void)
{
uchar i;
DDRA|=_BV(0) |_BV(1)|_BV(2) ;//定義選通部分輸出
DDRC=0XFF;
PORTC&=~_BV(2);//使能初始低電
LCD_Init();
_delay_ms(5);
while(1);
{
LCD_Com_Write(0x80);//設(shè)置數(shù)據(jù)地址,從頭顯示
_delay_ms(5);
for(i=0;i<10;i++)//顯示字符在第一行
{
LCD_Data_Write(s);
_delay_ms(5);
}
}
}
|
|