#include <msp430g2553.h>signed char a[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09};signed char i=0;void main(void){WDTCTL = WDTPW | WDTHOLD;P2DIR |= BIT0; //P2.0方向设置为输出P2REN |= BIT2+BIT1; //P2.2上拉电阻使能P2OUT |= BIT2+BIT1; //P2.2设置为上拉P1DIR |= 0xff; //P1口设置为输出while(1){if(!(P2IN&0x04)){__delay_cycles(50000);if(!(P2IN&0x04)){while(!(P2IN&0x04));
i++;if(i > 9)i = 0;
P1OUT = a; //P1口输出对应数码管的值P2OUT &= ~BIT0; // 锁存进数码管__delay_cycles(80000);
}}
if(!(P2IN&0x02)){__delay_cycles(50000);if(!(P2IN&0x02)){while(!(P2IN&0x02));
i--;if(i < 0)i = 9;
P1OUT = a; //P1口输出对应数码管的值P2OUT &= ~BIT0; // 锁存进数码管__delay_cycles(80000);
}}
}}
求帮忙通过两个独立按键实现0~99加减
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>