全文预览

实验2单片机c语言程序结构

上传者:苏堤漫步 |  格式:docx  |  页数:18 |  大小:242KB

文档介绍
();};};return0;}voiddelay(){longintj;for(j=0;j<300000;j++);}实验3程序#include"io430.h"voidbuzz();voiddelay();intmain(void){//StopwatchdogtimertopreventtimeoutresetWDTCTL=WDTPW+WDTHOLD;unsignedcharLight1[8]={0x10,0x80,0x01,0x08,0x04,0x02,0x40,0x20};unsignedcharLight2[4]={0x28,0x14,0x41,0x82};unsignedchari,flag=0,key=0;P1DIR|=BIT7;P1SEL=0x00;P1SEL2=0x00;P1REN|=BIT1+BIT4;P1OUT=0xff;P2SEL=0x00;P2SEL2=0x00;P2DIR=0xff;P2OUT=0xff;while(1){if((P1IN&BIT4)==0){key=1;buzz();}elseif((P1IN&BIT1)==0){key=2;buzz();}if(key==1){while(1){for(i=0;i<=7;i++){P2OUT=~Light1[i];delay();if((P1IN&BIT1)==0){key=2;flag=1;break;}};if(flag==1){flag=0;buzz();break;}};}if(key==2){buzz();while(1){for(i=0;i<=3;i++){P2OUT=~Light2[i];delay();if((P1IN&BIT4)==0){key=1;flag=1;break;}};if(flag==1){flag=0;buzz();break;}};}P2OUT=0xff;

收藏

分享

举报
下载此文档