1、先来看引脚图
2、对IO口进行配置
3、配置端口的模式
4、延时函数,通过STC-ISP软件可以知道
5、程序
#include "stc8g.h"
#include "intrins.h"
sbit LED_R = P0^5;//红色LED
sbit LED_Y = P0^6;//黄色LED
sbit LED_G = P0^7;//绿色LED
void Delay1us()
{
unsigned char i;
_nop_();
_nop_();
i = 9;
while(--i);
}
void Delay1ms()
{
unsigned char i,j;
_nop_();
_nop_();
i = 46;
j = 113;
do{
while(--j);
}while(--i);
}
void Delay_ms(unsigned int ms)
{
while(ms--)
{
Delay1ms();
}
}
void main()
{
P0M0 = 0x00;//设置P0口为准双向口
P0M1 = 0x00;
LED_G = 0;
Delay_ms(5000);
LED_G = 1;
LED_Y = 0;
Delay_ms(500);
LED_Y = 1;
Delay_ms(500);
LED_Y = 0;
Delay_ms(500);
LED_Y = 1;
Delay_ms(500);
LED_Y = 1;
LED_R = 0;
Delay_ms(5000);
LED_R = 1;
while(1)
{
}
}