|
#include<stc89c51rc.h>
#define uchar unsigned char
#define uint unsigned int
#define light 3 //定義亮度
sbit SHCP=P3^6;//595的移位信號
sbit STCP=P3^5;//是595的鎖存信號
sbit SDA=P3^4;//紅數(shù)據(jù)
sbit IA=P1^0;//行控制線A
sbit IB=P1^1;//行控制線B
sbit IC=P1^2;//行控制線C
#define scan0 {IA=0;IB=0;IC=0;}
#define scan1 {IA=1;IB=0;IC=0;}
#define scan2 {IA=0;IB=1;IC=0;}
#define scan3 {IA=1;IB=1;IC=0;}
#define scan4 {IA=0;IB=0;IC=1;}
#define scan5 {IA=1;IB=0;IC=1;}
#define scan6 {IA=0;IB=1;IC=1;}
#define scan7 {IA=1;IB=1;IC=1;}
uchar line=0;
void rxd_data(); // 發(fā)送移動數(shù)據(jù)
uchar time_count=0; //計(jì)數(shù)
uchar reg=0;
/*****不影響其他端口的掃描*************************/
void scan(unsigned char Value)
{switch(Value)
{case 0: scan0;break;
case 1: scan1;break;
case 2: scan2;break;
case 3: scan3;break;
case 4: scan4;break;
case 5: scan5;break;
case 6: scan6;break;
case 7: scan7;break;
default:break;
}
}
/**************************************/
void Timer0Interrupt(void) interrupt 1 //定時器中斷
{
TH0 = 0x04C;//定時50MS 這里的晶振是18.432M 測試無需理會晶振大小
TL0 = 0x000;
time_count++;
if(time_count>10)//發(fā)送一次數(shù)據(jù)
{
time_count=0;
line++; //下一行
if(line>8) //共8行
{
line=0; //重新移動
}
rxd_data();//發(fā)送數(shù)據(jù)
scan(line); //打開行掃描
STCP=1;//鎖存
STCP=0;
}
}
/********************************************/
/*主函數(shù)*/
void main()
{ TMOD=0x01; //定時器0 16位定時定時器1方式2
TH0=0x4c; //50ms
TL0=0x00;
TR0=1; //開定時器計(jì)數(shù)
ET0=1; //開定時器中斷
EA=1; //開中斷
do
{
} while (1);
}
/***********************發(fā)送移動的數(shù)據(jù)****************************/
void rxd_data(void) //串行發(fā)送數(shù)據(jù)
{
uchar s;
uchar k;
for(s=0;s<4;s++)//發(fā)送4字節(jié)數(shù)據(jù) 一行4個字節(jié)
{
for(k=0;k<8;k++) //一個字節(jié)8位
{
SHCP=0; //上降沿移位595
SDA=1;
SHCP=1;
}
}
}
|
|