點亮其中一個燈
#include <reg52.h>
//LED2亮燈
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
sbit LED2 = P0 ^ 0;
void main()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
LED2 = 0;
while (1)
;
}
點亮所有燈,且不滅
#include <reg52.h>
//LED2~LED9依次亮燈後不滅
sbit LED2 = P0 ^ 0;
sbit LED3 = P0 ^ 1;
sbit LED4 = P0 ^ 2;
sbit LED5 = P0 ^ 3;
sbit LED6 = P0 ^ 4;
sbit LED7 = P0 ^ 5;
sbit LED8 = P0 ^ 6;
sbit LED9 = P0 ^ 7;
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
void main()
{
int i = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
LED2 = 0;
for (i = 0; i < 10000; i++)
;
LED3 = 0;
for (i = 0; i < 10000; i++)
;
LED4 = 0;
for (i = 0; i < 10000; i++)
;
LED5 = 0;
for (i = 0; i < 10000; i++)
;
LED6 = 0;
for (i = 0; i < 10000; i++)
;
LED7 = 0;
for (i = 0; i < 10000; i++)
;
LED8 = 0;
for (i = 0; i < 10000; i++)
;
LED9 = 0;
while (1)
;
}
依次點亮所有燈且滅
#include <reg52.h>
//LED2~LED9依次亮燈後滅燈
sbit LED2 = P0 ^ 0;
sbit LED3 = P0 ^ 1;
sbit LED4 = P0 ^ 2;
sbit LED5 = P0 ^ 3;
sbit LED6 = P0 ^ 4;
sbit LED7 = P0 ^ 5;
sbit LED8 = P0 ^ 6;
sbit LED9 = P0 ^ 7;
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
void main()
{
int i = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
LED2 = 0;
for (i = 0; i < 10000; i++)
;
LED2 = 1;
LED3 = 0;
for (i = 0; i < 10000; i++)
;
LED3 = 1;
LED4 = 0;
for (i = 0; i < 10000; i++)
;
LED4 = 1;
LED5 = 0;
for (i = 0; i < 10000; i++)
;
LED5 = 1;
LED6 = 0;
for (i = 0; i < 10000; i++)
;
LED6 = 1;
LED7 = 0;
for (i = 0; i < 10000; i++)
;
LED7 = 1;
LED8 = 0;
for (i = 0; i < 10000; i++)
;
LED8 = 1;
LED9 = 0;
for (i = 0; i < 10000; i++)
;
LED9 = 1;
while (1)
;
}
跑馬燈
#include <reg52.h>
//LED2~LED9依次亮燈後滅燈再次亮燈..跑馬燈
sbit LED2 = P0 ^ 0;
sbit LED3 = P0 ^ 1;
sbit LED4 = P0 ^ 2;
sbit LED5 = P0 ^ 3;
sbit LED6 = P0 ^ 4;
sbit LED7 = P0 ^ 5;
sbit LED8 = P0 ^ 6;
sbit LED9 = P0 ^ 7;
sbit ADDR0 = P1 ^ 0;
sbit ADDR1 = P1 ^ 1;
sbit ADDR2 = P1 ^ 2;
sbit ADDR3 = P1 ^ 3;
sbit ENLED = P1 ^ 4;
void main()
{
int i = 0;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while (1)
{
LED2 = 0;
for (i = 0; i < 10000; i++)
;
LED2 = 1;
LED3 = 0;
for (i = 0; i < 10000; i++)
;
LED3 = 1;
LED4 = 0;
for (i = 0; i < 10000; i++)
;
LED4 = 1;
LED5 = 0;
for (i = 0; i < 10000; i++)
;
LED5 = 1;
LED6 = 0;
for (i = 0; i < 10000; i++)
;
LED6 = 1;
LED7 = 0;
for (i = 0; i < 10000; i++)
;
LED7 = 1;
LED8 = 0;
for (i = 0; i < 10000; i++)
;
LED8 = 1;
LED9 = 0;
for (i = 0; i < 10000; i++)
;
LED9 = 1;
}
}