标签:
第一步,先聊聊单片机 LED 点亮:
#include <reg52.h>
sbit led1 = P1 ^ 2;
void delay(unsigned int xx)//延时
{
int i = 0;
while(xx--)
{
for(i = 0; i < 400; i++);
}
}
int main()
{
while(1)
{
led1 = 1//灭
delay(100);
led1 = 0;//亮
delay(100);
}
}
#include <S3C2440.h>
#define LED_A_ON(i) GPADAT &= ~(0x1 << i) //A口i灯亮
#define LED_B_ON(i) GPBDAT &= ~(0x1 << i) //B口i灯亮
#define LED_A_OFF(i) GPADAT |= (0x1 << i) //A口i灯亮
#define LED_B_OFF(i) GPBDAT |= (0x1 << i) //B口i灯亮
void LED_INIT(void);//初始化控制灯
void delay(unsigned int xx);//延时
int main()
{
LED_INIT();
while(1)//流水灯实验
{
LED_B_ON(5);
LED_B_OFF(6);
LED_A_OFF(25);
LED_A_OFF(26);
delay(100);
LED_B_ON(6);
LED_B_OFF(5);
LED_A_OFF(25);
LED_A_OFF(26);
delay(100);
LED_A_ON(25);
LED_B_OFF(5);
LED_B_OFF(6);
LED_A_OFF(26);
delay(100);
LED_A_ON(26);
LED_B_OFF(5);
LED_B_OFF(6);
LED_A_OFF(25);
delay(100);
}
}
void LED_INIT()//初始化控制灯
{
GPBCON &= ~(0x03 << 10);//GPB5清零
GPBCON |= (0x01 << 10); //置1
GPACON &= ~(0x3 << 25);
GPADAT |= (0x3 << 25);
GPBDAT |= (0x3 << 5);
delay(10000);
}
标签:
原文地址:http://www.cnblogs.com/jianghanxv/p/5521695.html