我想用一个数组显示0-9个数字,但是由于本人是菜鸟又没接触过ht1621,在网上下了个测试程序,现在可以把lcd每段都点亮,程序不是很能看懂,我想用一个数组显示0-9,我的lcd是4com 9seg下面是程序,请高手指点怎么修改。谢谢啦/*------------------------------------------------------------------------------MEASURE.C: Remote Measurement Recorder using the C51 COMPILER
Copyright 1990-2005 Keil Software, Inc.
------------------------------------------------------------------------------*/
#include<c:\Keil\C51\INC\STC\STC12c5a60S2.H> /* special function register declarations */
/* for the Philips P89C935 device */
#include <stdio.h> /* standard I/O .h-file */
#include <stdlib.h> /* standard library .h-file */
#include <ctype.h> /* character functions */
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define _Nop() _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_()
#define BIAS 0x50 //0X52 1/3ƫѹ,4±³¼« 0x50 1/2ƫѹ,
#define SYSDIS 0X00 //¹Ø±ÕϵͳÕñµ´Æ÷ºÍLCDƫѹ·¢ÉúÆ÷
#define SYSEN 0X02
#define LCDOFF 0X04 //¹Ø±Õƫѹ·¢ÉúÆ÷
#define LCDON 0X06 //´ò¿ªÆ«Ñ¹·¢ÉúÆ÷
#define XTAL 0x28 //ϵͳʱÖÓÔ´ ¾§Õñ
#define RC256 0X30 //ƬÄÚRCÕñµ´
#define TONEON 0X12 //´ò¿ªÉùÒô
#define TONEOFF 0X10 //¹Ø±ÕÉùÒô
#define WDTDIS 0X0A //½ûÖ¹¿´ÃŹ·
sbit HT1621_DAT=P1^5; //´®ÐÐÊý¾ÝÊäÈë/Êä³ö
sbit HT1621_CS=P1^1; //ƬѡÊäÈë
sbit HT1621_WR=P1^3; //Âö³åÊäÈë
sbit cs_sda = P3^5; //dog
uchar code Ht1621Tab[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
void Delay(uchar us)
{
while(--us);
}
void DelayMS(uint iMs)
{
uint i,j;
for(i=0;i<iMs;i++)
for(j=0;j<65;j++) Delay(1);
}
void Ht1621Wr_Data(uchar Data,uchar cnt)
{
uchar i;
for (i=0;i<cnt;i++)
{
HT1621_WR=0;
_Nop();
HT1621_DAT=Data&0x80;
_Nop();
HT1621_WR=1;
_Nop();
Data<<=1;
}
}
void Ht1621WrCmd(uchar Cmd)
{
HT1621_CS=0;
_Nop();
Ht1621Wr_Data(0x80,4);
Ht1621Wr_Data(Cmd,8);
HT1621_CS=1;
_Nop();
}
void Ht1621WrOneData(uchar Addr,uchar Data)
{
HT1621_CS=0;
Ht1621Wr_Data(0xa0,3);
Ht1621Wr_Data(Addr<<2,6);
Ht1621Wr_Data(Data<<4,4);
HT1621_CS=1;
_Nop();
}
void Ht1621WrAllData(uchar Addr,uchar *p,uchar cnt)
{
uchar i;
HT1621_CS=0;
Ht1621Wr_Data(0xa0,3);
Ht1621Wr_Data(Addr<<2,6);
for (i=0;i<cnt;i++)
{
Ht1621Wr_Data(*p,8);
p++;
}
HT1621_CS=1;
_Nop();
}
void Ht1621_Init(void)
{
HT1621_CS=1;
HT1621_WR=1;
HT1621_DAT=1;
DelayMS(2000);
cs_sda = ~cs_sda ;//
Ht1621WrCmd(BIAS);
Ht1621WrCmd(RC256);
Ht1621WrCmd(SYSDIS);
Ht1621WrCmd(WDTDIS);
Ht1621WrCmd(SYSEN);
Ht1621WrCmd(LCDON);
}
void main()
{
uchar i,j,t;
Ht1621_Init(); //Éϵç³õʼ»¯LCD
cs_sda = ~cs_sda ;
while(1){
Ht1621WrAllData(0,Ht1621Tab,16); //ÇåÆÁHt1621WrAllData(0,Ht1621Tab,16);
for (i=0;i<32;i++)
{
t=0x01;
for (j=0;j<4;j++)
{
Ht1621WrOneData(i,t);
t<<=1;
t++;
DelayMS(200);
cs_sda = ~cs_sda ;//
}
}
}
}
|