開關,接在 P2.7 與地之間。
#include
void w(unsigned char k)
{
unsigned int a; //定義變數a 為int 型別
if (k) {
while(P2_7); //沒有按就迴圈,等待按下
for (a = 0; a
while(P2_7); //沒有按就迴圈
}
else while(!P2_7); //按下就迴圈,等待鬆開
void main(void) //主函式名
while(1) {
w(1); P1_0 = 0; w(0); P1_0 = 1;
w(1); P1_1 = 0; w(0); P1_1 = 1;
w(1); P1_2 = 0; w(0); P1_2 = 1;
w(1); P1_3 = 0; w(0); P1_3 = 1;
w(1); P1_4 = 0; w(0); P1_4 = 1;
w(1); P1_5 = 0; w(0); P1_5 = 1;
w(1); P1_6 = 0; w(0); P1_6 = 1;
w(1); P1_7 = 0; w(0); P1_7 = 1;
開關,接在 P2.7 與地之間。
#include
void w(unsigned char k)
{
unsigned int a; //定義變數a 為int 型別
if (k) {
while(P2_7); //沒有按就迴圈,等待按下
for (a = 0; a
while(P2_7); //沒有按就迴圈
}
else while(!P2_7); //按下就迴圈,等待鬆開
}
void main(void) //主函式名
{
while(1) {
w(1); P1_0 = 0; w(0); P1_0 = 1;
w(1); P1_1 = 0; w(0); P1_1 = 1;
w(1); P1_2 = 0; w(0); P1_2 = 1;
w(1); P1_3 = 0; w(0); P1_3 = 1;
w(1); P1_4 = 0; w(0); P1_4 = 1;
w(1); P1_5 = 0; w(0); P1_5 = 1;
w(1); P1_6 = 0; w(0); P1_6 = 1;
w(1); P1_7 = 0; w(0); P1_7 = 1;
}
}