端口定義在程序里面采用8位數據模式,程序測試通過.
#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.zg4o1577.cn "
};
/**********************************/
/************延時子程序************/
/**********************************/
void delay(uint z)//延時
{
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
}
/**********************************/
/************讀數子程序************/
/**********************************/
void duzhi(uchar tee)//寫數子程序
{
PORTC|=BIT(6);//將RS控制端置1
PORTC&=~BIT(0);//將RW控制端置0
delay(10);
PORTA=tee;//將要讀的數放到PA口
PORTC|=BIT(0);//將使能端置0
delay(10);
PORTC&=~BIT(0);//將使能端置1
}
/**********************************/
/***************主程序*************/
/**********************************/
void main()
{
DDRA=0xff;
DDRC|=BIT(6)|BIT(7)|BIT(0);//將3個控制端全部設為輸出
PORTC&=~BIT(7);//將RW端置0
xeizhi(0x01);
xeizhi(0x38);
xeizhi(0x0c);
xeizhi(0x06);
/*******************第一行顯示****************/
xeizhi(0x80);//將數據放顯示區
for(shu=0;shu<15;shu++)
duzhi(table[shu]);
/*******************第二行顯示****************/
xeizhi(0xc0);//將數據放在顯示區
for(shu=0;shu<15;shu++)//查詢15次得到要顯示的數
duzhi(table1[shu]);//查表得到想要的數,和上面結合妙妙。
while(1);
}