專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> MCU設(shè)計(jì)實(shí)例 >> 瀏覽文章

AVR單片機(jī)1602液晶程序

作者:佚名   來源:本站原創(chuàng)   點(diǎn)擊數(shù):  更新時(shí)間:2012年06月09日   【字體:

端口定義在程序里面采用8位數(shù)據(jù)模式,程序測(cè)試通過.
#include <iom16v.h>
#include <macros.h>
#define  uchar unsigned char
#define  uint  unsigned int
#pragma data:code
uchar shu;
const uchar table[15]={
"yinqing@163.com"
};
const uchar table1[]={
" www.torrancerestoration.com  "
};
/**********************************/
/************延時(shí)子程序************/
/**********************************/
void delay(uint z)//延時(shí)
{
 uint x,y;
 for(x=500;x>0;x--)
 for(y=z;y>0;y--);
}
/**********************************/
/***********寫指令子程序***********/
/**********************************/
void xeizhi(uchar tem)//寫指令子程序
{
 PORTC&=~BIT(6);//將RS控制端置0
 PORTC&=~BIT(0);//將RW控制端置0
 delay(10);
 PORTA=tem;//將要讀的指令放到PA口
 PORTC|=BIT(0);//將使能端置0
 delay(10);
 PORTC&=~BIT(0);//將使能端置1
}
/**********************************/
/************讀數(shù)子程序************/
/**********************************/
void duzhi(uchar tee)//寫數(shù)子程序
{
 PORTC|=BIT(6);//將RS控制端置1
 PORTC&=~BIT(0);//將RW控制端置0
 delay(10);
 PORTA=tee;//將要讀的數(shù)放到PA口
 PORTC|=BIT(0);//將使能端置0
 delay(10);
 PORTC&=~BIT(0);//將使能端置1
}
/**********************************/
/***************主程序*************/
/**********************************/
void main()
{
  DDRA=0xff;
 DDRC|=BIT(6)|BIT(7)|BIT(0);//將3個(gè)控制端全部設(shè)為輸出
 PORTC&=~BIT(7);//將RW端置0
 xeizhi(0x01);
 xeizhi(0x38);
 xeizhi(0x0c);
 xeizhi(0x06);
/*******************第一行顯示****************/
 xeizhi(0x80);//將數(shù)據(jù)放顯示區(qū)
 for(shu=0;shu<15;shu++)
 duzhi(table[shu]);
/*******************第二行顯示****************/
 xeizhi(0xc0);//將數(shù)據(jù)放在顯示區(qū)
 for(shu=0;shu<15;shu++)//查詢15次得到要顯示的數(shù)
 duzhi(table1[shu]);//查表得到想要的數(shù),和上面結(jié)合妙妙啊!
 while(1); 
}

關(guān)閉窗口

相關(guān)文章