说明:看门狗定时器会到点整个系统自动复位,用来更新bug,系统的自我保护机制
**说明: 一般CON是控制输入输出 DAT控制具体的寄存器控制引脚 所以找对应的就好
开发手册很重要,要会搜索
循环点亮程序
清零和置一的方法可以和之前一样制定要的那一位或和与 不过太长了不好写,一般采用这种移位的方式
void delay(volatile int d)
{
while (d--);
}
int main(void)
{
volatile unsigned int *pGPFCON = (volatile unsigned int *)0x56000050;
volatile unsigned int *pGPFDAT = (volatile unsigned int *)0x56000054;
int val = 0;
int tmp;
*pGPFCON &= ~((3<<8) | (3<<10) | (3<<12));
*pGPFCON |= ((1<<8) | (1<<10) | (1<<12));
while (1)
{
tmp = ~val;
tmp &= 7;
*pGPFDAT &= ~(7<<4);
*pGPFDAT |= (tmp<<4);
delay(100000);
val++;
if (val == 8)
val =0;
}
return 0;
}
另外后面采用把寄存器定义为宏,效果是一样的不写了
按键led程序
#include "s3c2440_soc.h"
void delay(volatile int d)
{
while (d--);
}
int main(void)
{
int val1, val2;
GPFCON &= ~((3<<8) | (3<<10) | (3<<12));
GPFCON |= ((1<<8) | (1<<10) | (1<<12));
GPFCON &= ~((3<<0) | (3<<4));
GPGCON &= ~((3<<6));
while (1)
{
val1 = GPFDAT;
val2 = GPGDAT;
if (val1 & (1<<0))
{
GPFDAT |= (1<<6);
}
else
{
GPFDAT &= ~(1<<6);
}
if (val1 & (1<<2))
{
GPFDAT |= (1<<5);
}
else
{
GPFDAT &= ~(1<<5);
}
if (val2 & (1<<3))
{
GPFDAT |= (1<<4);
}
else
{
GPFDAT &= ~(1<<4);
}
}
return 0;
}
|