標題:
AVR GCC 編寫的1602驅動程序
[打印本頁]
作者:
ZGQDIANZILUNTAN
時間:
2016-7-22 08:44
標題:
AVR GCC 編寫的1602驅動程序
用AVR GCC 編寫的1602驅動程序 為什么總是不顯示,求大神幫忙,謝謝了。
#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);//使能關閉
}
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);//使能關閉
}
void LCD_Init()
{
DDRC=0XFF;
DDRA=0XFF;
_delay_ms(15);
LCD_Com_Write(0x38);//設置顯示模式
_delay_ms(5);
LCD_Com_Write(0x38);//設置顯示模式
_delay_ms(5);
LCD_Com_Write(0x38);//設置顯示模式
_delay_ms(5)
LCD_Com_Write(0x38);//設置顯示模式
_delay_ms(5);
LCD_Com_Write(0x08);//顯示關閉
_delay_ms(5);
LCD_Com_Write(0x01);//顯示清屏
_delay_ms(5)
LCD_Com_Write(0x0F);//光標和背景設置
_delay_ms(5);
LCD_Com_Write(0x06);//光標設置,和數(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ù)據(jù)地址,從頭顯示
_delay_ms(5);
for(i=0;i<10;i++)//顯示字符在第一行
{
LCD_Data_Write(s
);
_delay_ms(5);
}
}
}
作者:
ZGQDIANZILUNTAN
時間:
2016-8-17 14:49
已解決
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1