|
給你寫(xiě)一個(gè)可變速花樣流水燈示例。沒(méi)有用如何難懂的語(yǔ)句,你一看就該明白。 #include <reg52.h> //#include "STC90C5xAD.h" #include "intrins.h" #define u16 unsigned int #define u8 unsigned char sbit key1=P3^2;//速度選擇 sbit key2=P3^3;//花樣選擇 //花樣流水燈數(shù)組 u8 code table1[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; u8 code table2[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe}; u8 code table3[]={0x00,0x81,0xc3,0xe7,0xff,0x7e,0x3c,0x18}; u8 code table4[]={0x18,0x3c,0x7e,0xff,0xe7,0xc3,0x81,0x00}; u8 a=1,b=1,c=0;//速度變量、花樣變量、選通變量 bit d=0; //計(jì)時(shí)標(biāo)志 u16 tt=0;//中斷計(jì)數(shù)變量 void delay(u16 z) { u16 x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void init() { TMOD=0x01; TH0=(65536-1000)/256;//1ms TL0=(65536-1000)%256;//1ms TR0=1; EA=1; ET0=1; } void main() { init(); while(1) { if(!key1) { delay(10); if(!key1) { a++; if(a>=5) a=1; while(!key1); } } if(!key2) { delay(10); if(!key2) { b++; if(b>=5) b=1; while(!key2); } } if(d==1) { d=0; if(b==1) P1=table1[c]; if(b==2) P1=table2[c]; if(b==3) P1=table3[c]; if(b==4) P1=table4[c]; c++; if(c>=8) c=0; } } } void t0() interrupt 1 { TH0=(65536-1000)/256;//1ms TL0=(65536-1000)%256;//1ms tt++; if(tt*a>=300) { tt=0; d=1; } } |
|