//*************************************************************************
#include "../head/config.h"
__CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);
//HS振荡,禁止看门狗,低压编程关闭,启动延时定时器
#define srclk RC3 //移位寄存器时钟 (74595:11脚)
#define rclk RC4 //存储寄存器时钟 (74595:12脚)
#define ser RC5 //串行数据口 (74595:14脚)
//oe:输出允许 L:允许输出;H:禁止输出; (74595:13脚)
//srclr:移位寄存器清零 (L:清零) (74595:10脚)
const uchar smg_text[]={0xbf,0xfe,0xfb,0xef,0xdf,0x7f,0xfd,0xf7,};
const uchar smg[]={0x0a,0xfa,0x8c,0xa8,0x78,0x29,0x09,0xba,0x08,0x28,0x00,};
// 0 1 2 3 4 5 6 7 8 9 all
const uchar smg_bit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff,};
uchar c;
uchar d;
//********************函数定义*********************
void delay1ms(uint DelayTime);
void senddata_74595(uchar SendData);
//*************** 主程序 ********************
void main(void)
{
TRISC3=0; //srclk 引脚设为输出
TRISC5=0; //ser 引脚设为输出
TRISC4=0; //rclk 引脚设为输出
rclk=0;
delay1ms(10);
rclk=0; //产生锁存时钟
senddata_74595(0x00);
senddata_74595(0x00);
rclk=1;
delay1ms(500);
while(1)
{
for(c=0;c<10;c++)
{
for(d=0;d<30;d++)
{
rclk=0;
senddata_74595(smg_bit[0]);
senddata_74595(smg[c]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[1]);
senddata_74595(smg[(c+1)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[2]);
senddata_74595(smg[(c+2)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[3]);
senddata_74595(smg[(c+3)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[4]);
senddata_74595(smg[(c+4)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[5]);
senddata_74595(smg[(c+5)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[6]);
senddata_74595(smg[(c+6)%10]);
rclk=1;
delay1ms(1);
rclk=0;
senddata_74595(smg_bit[7]);
senddata_74595(smg[(c+7)%10]);
rclk=1;
delay1ms(1);
}
}
}
}
//***********************74595发送函数************************
void senddata_74595(uchar SendData)
{
uchar i;
for(i=0;i<8;i++)
{
if((SendData&0x80)==0) //先发送高位,后发送低位
{
ser=0;
}
else
{
ser=1;
}
srclk=0;
srclk=1;
SendData=SendData<<1; //数据左移一位
}
}
//*****************延时 n*1ms 12MHz*****************
void delay1ms(uint DelayTime)
{
uint temp;
for(;DelayTime>0;DelayTime--)
{
for(temp=0;temp<270;temp++)
{;}
}
}