//*************************************************************************#include #include "../head/config.h"__CONFIG(HS&WDTDIS&LVPDIS&PWRTEN);//HS振蕩,禁止看門狗,低壓編程關(guān)閉,啟動延時定時器#define srclk RC3 //移位寄存器時鐘 (74595:11腳)#define rclk RC4 //存儲寄存器時鐘 (74595:12腳)#define ser RC5 //串行數(shù)據(jù)口 (74595:14腳)//oe:輸出允許 L:允許輸出;H:禁止輸出; (74595:13腳)//srclr:移位寄存器清零 (L:清零) (74595:10腳)constuchar smg_text[]={0xbf,0xfe,0xfb,0xef,0xdf,0x7f,0xfd,0xf7,};constuchar smg[]={0x0a,0xfa,0x8c,0xa8,0x78,0x29,0x09,0xba,0x08,0x28,0x00,};// 0 1 2 3 4 5 6 7 8 9 allconstuchar smg_bit[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0xff,};uchar c;uchar d;//********************函數(shù)定義*********************voiddelay1ms(uint DelayTime);voidsenddata_74595(uchar SendData);//*************** 主程序 ********************voidmain(void){TRISC3=0; //srclk 引腳設(shè)為輸出TRISC5=0; //ser 引腳設(shè)為輸出TRISC4=0; //rclk 引腳設(shè)為輸出rclk=0;delay1ms(10);rclk=0; //產(chǎn)生鎖存時鐘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發(fā)送函數(shù)************************voidsenddata_74595(uchar SendData){uchar i;for(i=0;i<8;i++){if((SendData&0x80)==0) //先發(fā)送高位,后發(fā)送低位{ser=0;}else{ser=1;}srclk=0;srclk=1;SendData=SendData<<1; //數(shù)據(jù)左移一位}}//*****************延時 n*1ms 12MHz*****************voiddelay1ms(uint DelayTime){uint temp;for(;DelayTime>0;DelayTime--){for(temp=0;temp<270;temp++){;}}}