jeff 的要求!! 大部分的時間都在除錯!! 下載開關快被扳断了!! 居然變數不能用 dc !!
isp介面
stc-isp
/* 20120731 變數名稱 dc 不可以,會亂跑,原因不明 改成 dca dcb 就可以11 , 計時 分秒 45秒之後顯示 HI JEFF HOW ARE YOU!! SW P1^2 選擇LED 顏色 */
#include<reg52.h>
#include <intrins.h> //use nop
//#include <delay.h>
sbit LATCH = P2^4; //byte 1 green Byte 2 RED
sbit SRCLK= P2^5;
sbit SER = P2^3;// Lo active pull down LED cathode to ground
sbit LATCH_B = P2^1;//LED commond Lo active
sbit SRCLK_B= P2^2;
sbit SER_B= P2^0;// LED commond Lo active to supply 5V to LED
sbit ch_color=P1^2;
unsigned char cd,color,ms2,ms3;
unsigned char dca,dcb;
unsigned char disp[24];//存放 4字24byte的資料給顯示
unsigned char dispbf[4];//={1,2,3,4};
bit ch_flag;//need flash count display
void DelayMs(unsigned char t);
void DelayUs2x(unsigned char t);
unsigned char code font6x11[] =
{0x00, 0x00, 0x00, 0x00, 0x00, //SP
0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H
0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x00,//I
0x00, 0x00, 0x00, 0x00, 0x00,//SP
0x00,0x20,0x40,0x41,0x41,0x3f,0x00,0x00,//J
0x00,0x7f,0x49,0x49,0x49,0x41,0x00,0x00,//E
0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F
0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F
0x00, 0x00, 0x00, 0x00, 0x00,//SP
0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H
0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,//O
0x00,0x3f,0x60,0x38,0x60,0x3f,0x00,0x00,//W
0x00,0x00,0x00,0x00,0x00,//SP
0x00,0x7c,0x12,0x11,0x12,0x7c,0x00,0x00,//A
0x00,0x7f,0x09,0x19,0x29,0x46,0x00,0x00,//R
0x00,0x7f,0x49,0x49,0x49,0x41,0x00,0x00,//E
0x00,0x00,0x00,0x00,0x00,//SP
0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00,//Y
0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,//O
0x00,0x3f,0x40,0x40,0x40,0x3f,0x00,0x00,//U
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x00, //!
0x00,0x20,0x20,0x20,0x20,0x20,0x20,0x00,//!
0x00,0x00,0x00,0x42,0x41,0x7f,0x40,0x40,//1
0x00,0x00,0x42,0x61,0x51,0x49,0x46,0x00,//2
0x00,0x22,0x41,0x41,0x49,0x49,0x3e,0x00,//3
0x00,0x30,0x28,0x24,0x22,0x7f,0x20,0x00,//4
0x00,0x4f,0x49,0x49,0x49,0x49,0x79,0x00,//5
0x00,0x7f,0x49,0x49,0x49,0x49,0x79,0x00,//6
0x00,0x01,0x61,0x11,0x09,0x05,0x03,0x00,//7
0x00,0x7f,0x49,0x49,0x49,0x49,0x7f,0x00,//8
0x00,0x4f,0x49,0x49,0x49,0x49,0x7f,0x00,//9
0x00,0x7f,0x41,0x41,0x41,0x41,0x7f,0x00,//0
0x00,0x7c,0x12,0x11,0x12,0x7c,0x00,0x00,//A 20120728
0x00,0x7f,0x49,0x49,0x49,0x36,0x00,0x00,//B
0x00,0x1c,0x22,0x41,0x41,0x22,0x00,0x00,//C
0x00,0x7f,0x41,0x41,0x22,0x1c,0x00,0x00,//D
0x00,0x7f,0x49,0x49,0x49,0x41,0x00,0x00,//E
0x00,0x7f,0x09,0x09,0x09,0x01,0x00,0x00,//F
0x00,0x1c,0x22,0x41,0x49,0x79,0x00,0x00,//G
0x00,0x7f,0x08,0x08,0x08,0x7f,0x00,0x00,//H
0x00,0x00,0x41,0x7f,0x41,0x00,0x00,0x00,//I
0x00,0x20,0x40,0x41,0x41,0x3f,0x00,0x00,//J
0x00,0x7f,0x08,0x14,0x22,0x41,0x00,0x00,//K
0x00,0x7f,0x40,0x40,0x40,0x40,0x00,0x00,//L
0x00,0x7f,0x02,0x04,0x02,0x7f,0x00,0x00,//M
0x00,0x7f,0x02,0x04,0x08,0x10,0x7f,0x00,//N
0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00,//O
0x00,0x7f,0x11,0x11,0x11,0x0e,0x00,0x00,//P
0x00,0x3e,0x51,0x51,0x21,0x5e,0x00,0x00,//Q
0x00,0x7f,0x09,0x19,0x29,0x46,0x00,0x00,//R
0x00,0x26,0x49,0X49,0x49,0x4a,0x30,0x00,//S
0x00,0x01,0x01,0x7f,0x01,0X01,0x00,0x00,//T
0x00,0x3f,0x40,0x40,0x40,0x3f,0x00,0x00,//U
0x00,0x1f,0x20,0x40,0x20,0x1f,0x00,0x00,//V
0x00,0x3f,0x60,0x38,0x60,0x3f,0x00,0x00,//W
0x00,0x63,0x14,0x08,0x14,0x63,0x00,0x00,//X
0x00,0x03,0x04,0x78,0x04,0x03,0x00,0x00,//Y
0x00,0x61,0x51,0x49,0x45,0x43,0x00,0x00//Z
};
unsigned char code tab[]={
0x00, 0x70, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x70, 0x00, 0x00,
0x00, 0x20, 0x60, 0x20, 0x20, 0x20, 0x20, 0x20, 0x70, 0x00, 0x00,
0x00, 0x70, 0x88, 0x08, 0x08, 0x10, 0x20, 0x48, 0xf8, 0x00, 0x00,
0x00, 0x70, 0x88, 0x08, 0x30, 0x08, 0x08, 0x10, 0xe0, 0x00, 0x00,
0x00, 0x10, 0x30, 0x50, 0x50, 0x90, 0xf8, 0x10, 0x10, 0x00, 0x00,
0x00, 0x38, 0x40, 0x60, 0x10, 0x08, 0x08, 0x08, 0x70, 0x00, 0x00,
0x00, 0x18, 0x20, 0x40, 0x70, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00,
0x00, 0x78, 0x48, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
0x00, 0x30, 0x48, 0x48, 0x30, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00,
0x00, 0x30, 0x48, 0x48, 0x48, 0x38, 0x08, 0x10, 0x60, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x90, 0x70, 0x90, 0x78, 0x00, 0x00,
0x00, 0xc0, 0x40, 0x40, 0x70, 0x48, 0x48, 0x48, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x38, 0x48, 0x40, 0x48, 0x30, 0x00, 0x00,
0x00, 0x30, 0x10, 0x10, 0x70, 0x90, 0x90, 0x90, 0x78, 0x00, 0x00};
/* 使用相對的位置來顯示出相對的自來 14:00
需要 相對的顯示如 WD[1] WD[2] WD[3] WD[4] 6*8
DISWD(x,y) x:位置 y:內容*/
// unsigned char DISPWD[4,6]//四個字每個字6BYTE
unsigned char code DP[10][6]={
{0x00,0x7f,0x41,0x41,0x41,0x7f},//0
{0x00,0x00,0x42,0x41,0x7f,0x40},//1
{0x00,0x42,0x61,0x51,0x49,0x46},//2
{0x00,0x22,0x41,0x49,0x49,0x3e},//3
{0x30,0x28,0x24,0x22,0x7f,0x20},//4
{0x00,0x4f,0x49,0x49,0x49,0x79},//5
{0x00,0x7f,0x49,0x49,0x49,0x79},//6
{0x00,0x61,0x11,0x09,0x05,0x03},//7
{0x00,0x7f,0x49,0x49,0x49,0x7f},//8
{0x00,0x4f,0x49,0x49,0x49,0x7f}};//9
/*unsigned char code ttab[10,8]={
{0x00,0x00,0x00,0x42,0x41,0x7f,0x40,0x40},//1
{0x00,0x00,0x42,0x61,0x51,0x49,0x46,0x00},//2
{0x00,0x22,0x41,0x41,0x49,0x49,0x3e,0x00},//3
{0x00,0x30,0x28,0x24,0x22,0x7f,0x20,0x00},//4
{0x00,0x4f,0x49,0x49,0x49,0x49,0x79,0x00},//5
{0x00,0x7f,0x49,0x49,0x49,0x49,0x79,0x00},//6
{0x00,0x01,0x61,0x11,0x09,0x05,0x03,0x00},//7
{0x00,0x7f,0x49,0x49,0x49,0x49,0x7f,0x00},//8
{0x00,0x4f,0x49,0x49,0x49,0x49,0x7f,0x00},//9
{0x00,0x7f,0x41,0x41,0x41,0x41,-x7f,0x00}};//0 */
void Chk_SW(void)
{
if (!ch_color)// cjeck if change led color sw is pressed? Noise reject
{
DelayMs(10);// Delay & check again
if(!ch_color) //yes
{
while(!ch_color)
if(ch_color)
{
color++; //Color count increment
}
}
}
if(color>2)
{
color=0;
}
}
/*------------------------------------------------
timer initial
------------------------------------------------*/
void Init_Timer0(void)
{
TMOD |= 0x01; //mode 1,16bit timer
EA=1; //interrupt enable
ET0=1; //et0
TR0=1; //tr0
}
/*------------------------------------------------
service sub
------------------------------------------------*/
void Timer0_isr(void) interrupt 1
{
TH0=(65536-2000)/256; //reset 2ms
TL0=(65536-2000)%256;
ms2++;// 2ms setflag
if(ms2>100)//2*250*4=2000ms
{
ms2=0;
ms3++;
Chk_SW();
}
if(ms3>5)
{
ms3=0;
ch_flag=1;//change display flash
dca++;//dc=1sec count
}
if(dca>59)
{
dcb++;
dca=0;
}
}
void DelayUs2x(unsigned char t)
{
while(--t);
}
void DelayMs(unsigned char t)
{
while(t--)
{
DelayUs2x(245);
DelayUs2x(245);
}
}
void SendByte(unsigned char dat,bit direction)
{
unsigned char i,temp;
if(direction==0)
temp=0x80;
else
temp=0x01;
for(i=0;i<8;i++)
{
SRCLK=0;
SER=dat&temp;
if(direction==0)
dat<<=1;
else
dat>>=1;
SRCLK=1;
}
}
void Send2Byte(unsigned char dat1,unsigned char dat2,bit direction)
{
SendByte(dat1,direction);
SendByte(dat2,direction);
}
void Out595(void)
{
LATCH=0;
_nop_();
LATCH=1;
}
void cd_pr (void)
{
dispbf[0]=dcb/10;
dispbf[1]=dcb%10;
dispbf[2]=dca/10;
dispbf[3]=dca%10;
}
void Dis_tr(void)
//程式 把資料送到 DISPWD[4,6]裡面資料顯示出來
{
unsigned char dp,d6p;
for(dp=0;dp<4;dp++)
{
for(d6p=0;d6p<6;d6p++)
{
//disp[d6p+dp*6]=0x49;
disp[d6p+dp*6+1]=DP[dispbf[dp]][d6p];// DP內部放著0~9的字库 對應1~4位數的dp,以及每一位數的6個byte的點陣 DP[dispbf[dp],d6p];
}
}
}
void Display (void)
{
unsigned char l,i,datx;
for(l=0;l<15;l++)//顯示5次
{
datx=0x00;//fe;//low active
for(i=24;i>0;i--) // 字型會反轉 (正 24>>0)
{
SRCLK_B=0;//----- sendseg start
SER_B=datx;//&0x80;
SRCLK_B=1;
LATCH_B=0; //
_nop_();
LATCH_B=1;
datx<<=1;
datx|=0x01;//------ sendseg end
Send2Byte(~disp,~disp,1);//"~" 明暗反轉 第一字紅色後面 第二字前面綠色
//把disp[24]內容show 出
Out595();
DelayUs2x(250);
Send2Byte(0xff,0xff,1);// 0 字正 1 字顛倒
Out595();
}//for i
}//for l
}
void normal_disp(void)
{
unsigned char i,datx,l;
unsigned int k;
for(k=0;k<128;k++) //流動方向 由左到右 88>>0
{
for(l=0;l<3;l++)
{
datx=0x00;//fe;//low active
for(i=24;i>0;i--) // 字型會反轉 (正 24>>0)
{
SRCLK_B=0;//----- sendseg start
SER_B=datx;//&0x80;
SRCLK_B=1;
LATCH_B=0; //
_nop_();
LATCH_B=1;
datx<<=1;
datx|=0x01;//------ sendseg end
if (color==0)// If(d_flag)//
{
Send2Byte(~font6x11[i+k+8],~font6x11[i+k+8],1);//"~" 明暗反轉 第一字紅色後面 第二字前面綠色
}
if (color==1)// if(g_flag)//
{
Send2Byte(0xff,~font6x11[i+k+8],1);//"~" 明暗反轉 第一字紅色後面 第二字前面綠色
}
if (color==2)// if(r_flag)//
{
Send2Byte(~font6x11[i+k+8],0xff,1);//"~" 明暗反轉 第一字紅色後面 第二字前面綠色
}
Out595();
DelayUs2x(250);
Send2Byte(0xff,0xff,1);// 0 字正 1 字顛倒
Out595();
}//for i
}//for l
}//for k
cd++;
}//while cd<2
main()
{
Init_Timer0();
while(1)
{
if(dca<45)
{
cd_pr();//轉換把 cd 轉成數字
Dis_tr();//把 數字轉成 24byte
Display();
}
else{
normal_disp();
}
}
}//main
|