基于mini2440轮询控制LED(裸机代码)
程序员文章站
2022-06-20 23:45:38
[cpp]
#define global_clk
#include "def.h" ...
[cpp]
#define global_clk
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#define led1_on rgpbdat = ((0xf<<5)^(1<<5)) //gpb5=0
#define led2_on rgpbdat = ((0xf<<5)^(1<<6)) //gpb6=0
#define led3_on rgpbdat = ((0xf<<5)^(1<<7)) //gpb7=0
#define led4_on rgpbdat = ((0xf<<5)^(1<<8)) //gpb8=0
#define led1_3_on rgpbdat = ((0xf<<5)^(5<<5)) //gpb5=0,gpb7=0
#define led2_4_on rgpbdat = ((0xf<<5)^(5<<6)) //gpb6=0,gpb8=0
#define led_off rgpbdat = (0xf<<5) //gpb5=1,gpb6=1,gpb7=1,gpb8=1
#define led_on rgpbdat = ~(0xf<<5) //gpb5=0,gpb6=0,gpb7=0,gpb8=0
int main() /*gpg0 gpg3 gpg5 gpg6 gpg7 gpg11 设置为输入*/
{ rgpgcon = ((0<1)|(0<7)|(0<11)|(0<13)|(0<15)|(0<23));
rgpbcon = ((1<10)|(1<12)|(1<14)|(1<16));//b口gpb5-6-7-8设为输出
led_off;
while( 1 )
{
if (rgpgdat&(1<<0)) //如果k1没有被按下
{
led_off;
}
else
{
led1_on;
}
if (rgpgdat&(1<<3)) //如果k2没有被按下
{
led_off;
}
else
{
led2_on;
}
if (rgpgdat&(1<<5)) //如果k3没有被按下
{
led_off;
}
else
{
led3_on;
}
if (rgpgdat&(1<<6)) //如果k4没有被按下
{
led_off;
}
else
{
led4_on;
}
if (rgpgdat&(1<<7)) //如果k5没有被按下
{
led_off;
}
else
{
led1_3_on;
}
if (rgpgdat&(1<<11)) //如果k6没有被按下
{
led_off;
}
else
{
led2_4_on;
}
}
return 0;
}
#define global_clk
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#define led1_on rgpbdat = ((0xf<<5)^(1<<5)) //gpb5=0
#define led2_on rgpbdat = ((0xf<<5)^(1<<6)) //gpb6=0
#define led3_on rgpbdat = ((0xf<<5)^(1<<7)) //gpb7=0
#define led4_on rgpbdat = ((0xf<<5)^(1<<8)) //gpb8=0
#define led1_3_on rgpbdat = ((0xf<<5)^(5<<5)) //gpb5=0,gpb7=0
#define led2_4_on rgpbdat = ((0xf<<5)^(5<<6)) //gpb6=0,gpb8=0
#define led_off rgpbdat = (0xf<<5) //gpb5=1,gpb6=1,gpb7=1,gpb8=1
#define led_on rgpbdat = ~(0xf<<5) //gpb5=0,gpb6=0,gpb7=0,gpb8=0
int main() /*gpg0 gpg3 gpg5 gpg6 gpg7 gpg11 设置为输入*/
{ rgpgcon = ((0<1)|(0<7)|(0<11)|(0<13)|(0<15)|(0<23));
rgpbcon = ((1<10)|(1<12)|(1<14)|(1<16));//b口gpb5-6-7-8设为输出
led_off;
while( 1 )
{
if (rgpgdat&(1<<0)) //如果k1没有被按下
{
led_off;
}
else
{
led1_on;
}
if (rgpgdat&(1<<3)) //如果k2没有被按下
{
led_off;
}
else
{
led2_on;
}
if (rgpgdat&(1<<5)) //如果k3没有被按下
{
led_off;
}
else
{
led3_on;
}
if (rgpgdat&(1<<6)) //如果k4没有被按下
{
led_off;
}
else
{
led4_on;
}
if (rgpgdat&(1<<7)) //如果k5没有被按下
{
led_off;
}
else
{
led1_3_on;
}
if (rgpgdat&(1<<11)) //如果k6没有被按下
{
led_off;
}
else
{
led2_4_on;
}
}
return 0;
}
下一篇: php中的PHP_EOL换行符详细解析