嵌入式--arm

时间:2021-04-13 05:14:04

两年前的东西了,整理一下,说不定以后就会用到了。

arm对于s3c2440的这个arm的驱动的整理。

其中包括:adc,beeper 蜂鸣器,key 按键,rtc ,timer定时器,UART等的驱动。

项目地址(github):https://github.com/yanjinyun/armS3c2440Drive

嵌入式--arm

****************
这是adc的驱动

#include "s3c2440.h"

#if 0
void niuniu(void)
{
uart_init();
adc_init(); adc_read(); while()
{
itoa(adc_read());
delay();
}
}
#endif #if ADSTART==0
void niuniu(void)
{
uart_init();
adc_init();
beeper_init(); adc_read(); while()
{
itoa(adc_read());
if(adc_read() > )
{
beeper_on();
}
else
{
beeper_off();
}
delay();
}
}
#endif #if ADSTART==1
void niuniu(void)
{
uart_init();
adc_init();
beeper_init(); while()
{
adc_enable();
itoa(adc_read());
if(adc_read() > )
{
beeper_on();
}
else
{
beeper_off();
}
delay();
}
}
#endif

********************
蜂鸣器的驱动:

#include "s3c2440.h"

#if 0
void niuniu(void)
{
beeper_init(); while()
{
beeper_on();
delay();
beeper_off();
delay();
}
}
#endif #if 1
void niuniu(void)
{
key_init();
beeper_init(); while()
{
if(key_on() == )
{
beeper_on();
}
else
{
beeper_off();
}
}
}
#endif

***************************
这个是按键的驱动key

#include "s3c2440.h"

#if 0
// 按键轮巡方式
void niuniu(void)
{
led_init();
key_init(); while()
{
if(key_on() == )
{
led_on();
}
else
{
led_off();
}
}
}
#endif #if 1
// 按键中断方式
void niuniu(void)
{
beeper_init();
key_init();
extint_init();
int_init();
uart_init(); while()
{
puts("key int mode\r\n");
delay();
}
}
#endif

**************************
这个是Led灯的驱动:

#include "s3c2440.h"

void niuniu(void)
{
led_init(); while()
{
led_on();
led_on();
delay();
led_off();
led_off();
delay();
}
}

这个是rtc的驱动

#include "s3c2440.h"
#include <string.h>
#include <stdlib.h> #if 0
void niuniu(void)
{
int time[];
char buf[], *p[];
int i; uart_init(); while()
{
puts("\r\nrtc> ");
gets(buf);
buf[strlen(buf)-] = '\0';
p[] = strtok(buf, " ");
for(i=; p[i-]!=NULL; i++)
{
p[i] = strtok(NULL, " ");
} if(strcmp(p[], "timeset") == )
{
time[] = atoh(p[]);
time[] = atoh(p[]);
time[] = atoh(p[]);
time[] = atoh(p[]);
time[] = atoh(p[]);
time[] = atoh(p[]);
time[] = atoh(p[]);
rtc_init(time);
} if(strcmp(p[], "time") == )
{
rtc_display();
}
}
}
#endif #if 1
void niuniu(void)
{
uart_init();
int_init();
alarm_init();
beeper_init(); while()
{
rtc_display();
sleep();
}
}
#endif

这个是定时器的驱动:

#include "s3c2440.h"

void niuniu(void)
{
int_init();
timer_init();
beeper_init();
uart_init(); timer_update(); while()
{
puts("haha ......\r\n");
sleep();
}
}

这个是UART的定时器的驱动:

#include "s3c2440.h"
#include <string.h> #if 0
void niuniu(void)
{
char buf[]; uart_init(); while()
{
puts("send: ");
gets(buf);
puts("\nrecv: ");
puts(buf);
}
}
#endif #if 1
void niuniu(void)
{
char buf[];
char *p[];
int i; beeper_init();
led_init();
uart_init(); while()
{
puts("\r\nuart> ");
gets(buf);
// 去掉\r\n
buf[strlen(buf)-] = '\0';
// strtok函数会使用全局变量
p[] = strtok(buf, " ");
for(i=; p[i-]!=NULL; i++)
{
p[i] = strtok(NULL, " ");
} if(strcmp(p[], "ledon") == )
{
if(strcmp(p[], "all") == )
{
for(i=; i<; i++)
{
led_on(i);
}
}
else
{
for(i=; p[i]!=NULL; i++)
{
led_on(*p[i]-);
}
}
} if(strcmp(p[], "ledoff") == )
{
if(strcmp(p[], "all") == )
{
for(i=; i<; i++)
{
led_off(i);
}
}
else
{
for(i=; p[i]!=NULL; i++)
{
led_off(*p[i]-);
}
}
} if(strcmp(p[], "beeperon") == )
{
beeper_on();
} if(strcmp(p[], "beeperoff") == )
{
beeper_off();
}
}
}
#endif