由于是初次接触这个..所以有很多东西不是很懂:
1、首先是ht1621的初始化,给一个高电平脉冲,指的是CS端直接置1,还是先置0,再置1;
2、ht1621的数据传输时(比如写的模式),在WR由高电平变为低电平,和低电平变为高电平,这个时间最大和最小是多少,也就是说这个周期是多少;
3,下面根据自己写的一段程序,不知道哪里错了,就是没法显示数据
说一下自己程序的思路:只显示一个数码管的值,在0-9之间循环逐渐递增,时间是由定时器来完成的。下面就是我的程序了
#include<PIC18F25K22.h>
#define LCD_CS1 PORTCbits.RC7
#define LCD_CS2 PORTCbits.RC6
#define LCD_WR PORTCbits.RC5
#define LCD_DA PORTCbits.RC4
#define SCAN_KEY_A PORTAbits.RA3
#define SCAN_KEY_B PORTAbits.RA5
//#define POWER_KEY PORTAbits.RA4
#define LCD PORTBbits.RB1
#define uchar unsigned char
#define WRITEDATA 0x05
#define WRITECMD 0x04
#define BIAS 0x52 //0b1000 0101 0010 1/3duty 4com
#define SYSDIS 0X00 //0b1000 0000 0000 关振系统荡器和LCD偏压发生器
#define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器
#define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压
#define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压
#define XTAL 0x28 //0b1000 0010 1000 外部接时钟
#define RC256 0X30 //0b1000 0011 0000 内部时钟
#define TONEON 0X12 //0b1000 0001 0010 打开声音输出
#define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出
#define WDTDIS 0X0A //0b1000 0000 1010 禁止看门狗
#define HIGHLEVEL 1
#define LOWLEVEL 0
#define ONES 1
#define TWOS 2
#define NOP() asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop");asm("nop")
const uchar ScreenAddHigh[2][16]={{1,3,5,11,8,10,13,15,17,31,20,22,24,30,27,29},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
const uchar ScreenAddLow[2][16]={{0,2,4,6,7,9,12,14,16,18,19,21,23,25,26,28},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
const uchar ScreenDataO[1][10]={{0XBF,0X07,0XDD,0X5F,0X67,0X7D,0XED,0X17,0XFF,0X77}};
const uchar ScreenDataT[1][10]={{0XBF,0X07,0XDD,0X5F,0X67,0X7D,0XED,0X17,0XFF,0X77}};
uchar Count;
void DelayUS(uchar us) //delay us
{
while(--us);
}
void DelayMS(uchar iMs) //delay ms
{
uchar i,j;
for(i=0;i<iMs;i++)
for(j=0;j<65;j++)
DelayUS(1);
}
void InitSet(); //初始化
void TransmitToHt(uchar Data,uchar Digit); //这个是传送数据的
void WriteToHt(uchar Data,uchar Address); //这个是写入DATA和地址数据的
void WriteCmdHt(uchar Cmd); //这个是写入命令数据的
void DisplayScreen(uchar CooSN,uchar Coordinate,uchar Data);//这个是我的自己想的一种方法,就是将频幕设置成坐标点,话剧话
//说,就是将每8位设置一个坐标,那么32个就可以分为16个坐标点,第一个参数是屏
//幕的坐标,由于我需要显示多个频幕(这个可以忽略不计),第二个参数是在一个屏幕里的坐标了,这个
//坐标是自己定义的,最后一个参数是数据。不知道说清楚了没。
void main()
{
InitSet();
while(1)
{
switch(Count)
{
case 0:
{
DisplayScreen(ONES,0,0);
break;
}
case 1:
{
DisplayScreen(ONES,0,1);
break;
}
case 2:
{
DisplayScreen(ONES,0,2);
break;
}
case 3:
{
DisplayScreen(ONES,0,3);
break;
}
case 4:
{
DisplayScreen(ONES,0,4);
break;
}
case 5:
{
DisplayScreen(ONES,0,5);
break;
}
case 6:
{
DisplayScreen(ONES,0,6);
break;
}
case 7:
{
DisplayScreen(ONES,0,7);
break;
}
case 8:
{
DisplayScreen(ONES,0,8);
break;
}
case 9:
{
DisplayScreen(ONES,0,9);
break;
}
default :break;
}
}
}
void interrupt ISR(void)
{
if(TMR0IF&&TMR0IE)
{
++Count;
if(Count==10)
{
Count=0;
}
TMR0IF=0;
}
}
void InitSet()
{
Count=0;
LCD_CS1=1;
LCD_CS2=1;
LCD_DA=1;
LCD_WR=1;
DelayMS(2000);
WriteCmdHt(BIAS);
WriteCmdHt(RC256);
WriteCmdHt(SYSDIS);
WriteCmdHt(WDTDIS);
WriteCmdHt(SYSEN);
WriteCmdHt(LCDON);
TRISC=0b0000000;
ANSC2=0;
ANSC3=0;
ANSC4=0;
ANSC5=0;
ANSC6=0;
ANSC7=0;
GIE=1;
PEIE=1;
TMR0ON=1;
T08BIT=0;
T0CS=0;
T0SE=1;
PSA=1;
//T0PS0=1;
//T0PS1=1;
//T0PS2=1;
TMR0IE=1;
TMR0IF=0;
}
void TransimToHt(uchar Data,uchar Digit)
{
uchar i;
uchar Tem=0x01;
for(i=0;i<Digit;i++)
{
LCD_WR=LOWLEVEL;
LCD_DA=Data&Tem; //Transim Low Digit
NOP();
LCD_WR=HIGHLEVEL;
NOP();
Data>>=1;
}
}
void WriteToHt(uchar Data,uchar Address)
{
LCD_CS1=LOWLEVEL;
NOP();
TransimToHt(WRITEDATA,3);
TransimToHt(Address,6);
TransimToHt(Data,4);
LCD_CS1=HIGHLEVEL;
NOP();
}
void WriteCmdHt(uchar Cmd)
{
LCD_CS1=LOWLEVEL;
NOP();
TransimToHt(WRITECMD,3);
TransimToHt(Cmd,9);
LCD_CS1=HIGHLEVEL;
NOP();
}
void DisplayScreen(uchar CooSN,uchar Coordinate,uchar Data)
{
uchar DataLow,DataHigh;
uchar LowAddress,HighAddress;
if(CooSN==ONES)
{
DataHigh=ScreenDataO[Coordinate][Data]/0x10;
DataLow=ScreenDataO[Coordinate][Data]%0x10;
}
else
{
DataHigh=ScreenDataT[Coordinate][Data]/0x10;
DataLow=ScreenDataT[Coordinate][Data]%0x10;
}
LowAddress=ScreenAddLow[CooSN][Coordinate];
HighAddress=ScreenAddHigh[CooSN][Coordinate];
WriteToHt(DataHigh,HighAddress);
WriteToHt(DataLow,LowAddress);
}
|
|