#include"config.h"
#include"port.h"
#include<ctype.h>
static volatile char SegBuf[8];
static volatile char CursorX;
#define STR P1_4
#define LED P1_2
void DispClear(void)
{
unsigned char i;
CursorX = 0;
for (i=0;i<8;i++){
SegBuf[i]=0x00;
}
}
void DispInit(void)
{
DispClear();
TMOD &= 0x0f;
TMOD |= 0X10;
//TL1=0XFE;//LOW_BYTE(65536UL-CPUCLK/(8*1000)); //扫描频率:75HZ T=0.0133s
//TH1=0XFF;//HIGH_BYTE(65536UL-CPUCLK/(8*1000));
TR1 = 1;
ET1 = 1;
EA = 1;
//SPI初始化:中断禁止,MSB,
STR = 1;
SPCR = 0X53;
SPSR &= ~(SPIF|SPWCOL);
}
static void HC595_write(char d)
{
SPDAT = d;
while(!(SPSR&SPIF));
SPSR&=~SPIF;
}
void DispCharPut(char c)
{
char t;
code char SegTabDec[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
code char SegTabHex[6]={0x77,0x7c,0x39,0x5e,0x79,0x71};
if(c=='.'){
t=(CursorX-1)&0x07;
SegBuf[t]|=0x80;
}
else{
if(c=='-') t=0x40;
else if(c=='r') t=0x50;
else if(isdigit(c)) t=SegTabDec[c-'0'];
else if(isxdigit(c)) t=SegTabHex[toupper(c)-'A'];
else t=0x00;
SegBuf[CursorX++]=t;
CursorX &= 0x07;
}
}
void DispStrPut(const char *s)
{
char c;
while(1)
{
c=*s++;
if(c=='\0')break;
DispCharPut(c);
}
}
void Timer1_ISR(void) interrupt 3
{
static unsigned char x =0;
static unsigned char dig = 0x01;
//LED=!LED;
//Timer1重装
//EA=0;
TR1=0;
TF1=0;
TL1=LOW_BYTE(65536UL-CPUCLK/(8*75)); //0XFD; //扫描频率:75HZ
TH1=HIGH_BYTE(65536UL-CPUCLK/(8*75)); //0XFD;
TR1=1;
//EA=1;
//向HC595写入数据
STR = 0 ;
HC595_write(~SegBuf[x]);
HC595_write(dig);
STR = 1;
//调整坐标位置和位选数据
x++;
x&=0x07;
dig <<= 1;
if(dig==0) dig = 0x01;
}
void main()
{
unsigned char x;
DispInit();
for(x=0;x<8;x++){
DispCharPut('1'+x);
}
while(1);
}
评论0