大家帮看看程序有没有问题
#include "pic.h"
#define uchar unsigned char
#define uint unsigned int
#define CS1 RB2
#define CS2 RB3
#define WR RB1
#define DATA RB0
#define BIAS 0x50 //0b1000 0101 0010 1/2duty 4com
#define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器
#define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压
#define TIMERDIS 0X08 //0b1000 0000 1000 时基输出失效
#define nop() NOP();NOP()
const uchar Ht1621Tab[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
const uchar Ht1621Tab1[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void delayms(uint x)
{
uchar j;
for(;x>0;x--)
{
for(j=0;j<40;j++);
}
}
void init()
{
ADCON1=0x07;
TRISA=0x00;
TRISB=0x00;
TRISC=0x00;
}
void SendBit_1621(uchar dat,uchar cnt)//DATA的高cnt位写入1621,高位在前
{
uchar i;
for(i=0;i<cnt;i++)
{
if((dat&0x80)==0)DATA=0;
else DATA=1;
WR=0;
NOP();
NOP();
NOP();
NOP();
WR=1;
NOP();
NOP();
NOP();
NOP();
dat<<=1;
}
}
void SendDataBit_1621(uchar dat,uchar cnt) //DATA的低cnt位写入1621,低高位在前
{
uchar i;
for(i=0;i<cnt;i++)
{
if((dat&0x01)==0)DATA=0;
else DATA=1;
WR=0;
NOP();
NOP();
NOP();
NOP();
delayms(50);
WR=1;
NOP();
NOP();
dat>>=1;
}
}
void SendCmd(uchar Cmd) //写命令
{
CS1=0;
CS2=0;
nop();
SendBit_1621(0x80,4); //写入命令标志100
SendBit_1621(Cmd,8); //写入9位数据,其中前8位为Cmd命令,最后1位任意
CS1=1;
CS2=1;
NOP();
NOP();
NOP();
NOP();
DATA=1;
}
void Write_1621_CS1(uchar Addr,uchar Data)
{
CS1=0;
SendBit_1621(0xa0,3); //写入数据标志101
SendBit_1621(Addr<<2,6); //写入6位地址数据
SendDataBit_1621(Data,4); //写入数据的低4位
CS1=1;
nop();
DATA=1;
NOP();
}
void Write_1621_CS2(uchar Addr,uchar Data)
{
CS2=0;
SendBit_1621(0xa0,3); //写入数据标志101
SendBit_1621(Addr<<2,6); //写入6位地址数据
SendDataBit_1621(Data,4); //写入数据的低4位
CS2=1;
nop();
DATA=1;
NOP();
}
void WriteAll_1621_CS1(uchar Addr,const uchar *p,uchar cnt)
{
uchar i;
CS1=0;
SendBit_1621(0xa0,3); //写入数据标志101
SendBit_1621(Addr<<2,6); //写入6位地址数据
for (i=0;i<cnt;i++)
{
SendDataBit_1621(*p,8); //写入数据
p++;
}
CS1=1;
nop();
}
void WriteAll_1621_CS2(uchar Addr,const uchar *p,uchar cnt)
{
uchar i;
CS2=0;
SendBit_1621(0xa0,3); //写入数据标志101
SendBit_1621(Addr<<2,6); //写入6位地址数据
for (i=0;i<cnt;i++)
{
SendDataBit_1621(*p,8); //写入数据
p++;
}
CS2=1;
nop();
}
void init1621()
{
CS1=1;
CS2=1;
WR=1;
DATA=1;
SendCmd(SYSEN);
SendCmd(LCDON);
SendCmd(BIAS);
SendCmd(TIMERDIS);
}
void main()
{
init();
init1621();
init1621();
while(1)
{
WriteAll_1621_CS1(0x00,Ht1621Tab,16);
WriteAll_1621_CS2(0x00,Ht1621Tab,16);
}
} |