#include<pic.h>
#define uchar unsigned char
uchar const table[]="ABCDEFGHIJKLMNOP";
uchar num;
uchar const table1[]="B";
unsigned int ys;
void _delay_ms(char a) //毫秒级延时子函数
{
unsigned char i,j;
for(i=0;i<a;i++)
for(j=0;j<40;j++);
}
void enable(void) //控制命令的子函数
{
PORTA = PORTA &0xfd;//1111 1101 a1置0
PORTA =PORTA &0xfb; //1111 1011 a2置0
PORTA =PORTA &0xf7; //1111 0111 a3置0
_delay_ms(9);
PORTA = PORTA | 0x08;//0000 1000 a3置1;给a3一个上升沿的脉冲
}
void main()
{
_delay_ms(9); //调用延时子程序
ADCON1=0x07; //设置RA口全部为普通数字IO口
TRISA=0x00; //定义RA口为输出
TRISC=0x00; //定义RC口为输出
_delay_ms(9);
PORTC=0x01; //清屏
enable();
PORTC=0x38; //设置8位2行5x7点阵
enable();
PORTC=0x0C; //设置显示器开、光标开、闪烁开
enable();
PORTC=0x06; //设置文字不动,光标自动右移
enable();
PORTC=0x80; //设置写入显示起始地址
enable();
PORTA=PORTA|0x02;
PORTA=PORTA&0xFB;
for (num=0;num<15;num++)
{
PORTC=table[num]; //显示的字符
PORTA =PORTA &0xf7; //1111 0111 a3置0
for(ys=10;ys>0;ys--);
PORTA = PORTA | 0x08;
}
enable();
PORTC=0xC0; //设置写入显示起始地址
enable();
PORTA=PORTA|0x02;
PORTA=PORTA&0xFB;
PORTC=table1[0]; //显示的字符
PORTA =PORTA &0xf7; //1111 0111 a3置0
for(ys=10;ys>0;ys--);
PORTA = PORTA | 0x08;
while(1); //while死循环
}
picc9.8的,供参考 |