资源描述:
《基于MSP430跑马灯程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#includevoidDelay(unsignedinttime){while(time--){_NOP();}}unsignedintFLASH_led[]=//跑马灯花样{0x0001,0x8000,0x0003,0xc000,0x0007,0xe000,0x000f,0xf000,0x001f,0xf800,0x003f,0xfc00,0x007f,0xfe00,0x00ff,0xff00,0x01ff,0xff80,0x03ff,0xffc0,0x07ff,0xffe0,0x0fff,0xff
2、f0,0x1fff,0xfff8,0x3fff,0xfffc,0x7fff,0xfffe,0xffff,0xffff,0x0005,0xa000,0x0015,0xa800,0x0055,0xaa00,0x0155,0xaa80,0x0555,0xaaa0,0x1555,0xaaa8,0x5555,0xaaaa};unsignedintTime_led[]=//跑马灯速度{0x0fff,0x1fff,0x2fff,0x3fff,0x4fff,0x5fff,0x6fff,0x7fff,0x8fff,0x9fff,0xafff,0xb
3、fff,0xcfff,0xdfff,0xefff,0xffff};intmain(void){unsignedchari;unsignedcharcount;//跑马灯花样计数unsignedcharcount_time=0;//跑马灯时间循环计数unsignedcharspeed_up=0;//加速标志位unsignedinttemp;WDTCTL=WDTPW+WDTHOLD;//关开门狗P3DIR
4、=BIT2;//使能跑马灯的电源信号P3OUT&=~BIT2;P8SEL=0X00;//配置P8.6,P8.7PADIR=0xff
5、ff;PAOUT=0x0000;//点亮全部LED,用于测试for(i=0;i<10;i++){Delay(0xffff);}while(1){for(count=0;count<46;count++){temp=FLASH_led[count];if(count%2==0)//正向旋转{for(i=0;i<16;i++){PAOUT=0xffff-temp;temp=temp<<1;Delay(Time_led[count_time]);}}else//反向旋转{for(i=0;i<16;i++){PAOUT=0xffff-te
6、mp;temp=temp>>1;Delay(Time_led[count_time]);}}}for(count=0;count<50;count++)//间隔旋转{if(count%2==0){PAOUT=0x5555;}else{PAOUT=0xaaaa;}Delay(Time_led[count_time]);}if(speed_up==0){count_time++;if(count_time==16)//计数到16则为一个周期{speed_up=1;}}else{count_time--;if(count_time==0
7、){speed_up=0;}}}}