回复 10楼 lianyicq
现在不知丢哪了。08年买的,上面从led灯到步进电机到串并口到液晶显示的都有,我好像只做了跑马灯和步进电机控制实验就丢一边没玩了。
能编个毛线衣吗?
#include <mcs51reg.h> #include <stdbool.h> void delay(unsigned int interval)//Delay function,unit is ms { unsigned int i; for(;interval>0;interval--) {for(i=0;i<124;i++) {;}} } unsigned char shift(unsigned char i,unsigned char j,bool direction)//loop shift function,j is bits { if (direction==true) return (i>>(8-j)|(i<<j)); else return (i<<(8-j)|(i>>j)); } unsigned char dis(unsigned char i) { unsigned char num[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; return num[i];} unsigned char bcd(unsigned char i)//8bits convert to 2*4bits BCD.Example 79(0100 1111) to 0111 1001 {return(((i/10)<<4)&0xf0 |(i%10));} void main(void) { //bool a=false; unsigned i; P1=0x00; i=30; while (P3_7) {;} for(;i>0;i--) { P2=bcd(i); delay(1000);} P2=bcd(0); P1=0x01; while(1) { P1=shift(P1,1,true); delay(200); } }