嵌入式--arm

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

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

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

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

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

#include "s3c2440.h"

#if 0
void niuniu(void)
{
    uart_init();
    adc_init();

    adc_read();

    while(1)
    {
        itoa(adc_read());
        delay(10000);
    }
}
#endif

#if ADSTART==0
void niuniu(void)
{
    uart_init();
    adc_init();
    beeper_init();

    adc_read();

    while(1)
    {
        itoa(adc_read());
        if(adc_read() > 2500)
        {
            beeper_on();
        }
        else
        {
            beeper_off();
        }
        delay(10000);
    }
}
#endif

#if ADSTART==1
void niuniu(void)
{
    uart_init();
    adc_init();
    beeper_init();

    while(1)
    {
        adc_enable();
        itoa(adc_read());
        if(adc_read() > 2500)
        {
            beeper_on();
        }
        else
        {
            beeper_off();
        }
        delay(10000);
    }
}
#endif

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

#include "s3c2440.h"

#if 0
void niuniu(void)
{
    beeper_init();

    while(1)
    {
        beeper_on();
        delay(10000);
        beeper_off();
        delay(10000);
    }
}
#endif

#if 1
void niuniu(void)
{
    key_init();
    beeper_init();

    while(1)
    {
        if(key_on(11) == 1)
        {
            beeper_on();
        }
        else
        {
            beeper_off();
        }
    }
}
#endif

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

#include "s3c2440.h"

#if 0
// 按键轮巡方式
void niuniu(void)
{
    led_init();
    key_init();

    while(1)
    {
        if(key_on(5) == 1)
        {
            led_on(1);
        }
        else
        {
            led_off(1);
        }
    }
}
#endif

#if 1
// 按键中断方式
void niuniu(void)
{
    beeper_init();
    key_init();
    extint_init();
    int_init();
    uart_init();

    while(1)
    {
        puts("key int mode
");
        delay(1000);
    }
}
#endif

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

#include "s3c2440.h"

void niuniu(void)
{
    led_init();

    while(1)
    {
        led_on(2);
        led_on(4);
        delay(10000);
        led_off(2);
        led_off(4);
        delay(10000);
    }
}

这个是rtc的驱动

#include "s3c2440.h"
#include <string.h>
#include <stdlib.h>

#if 0
void niuniu(void)
{
    int time[7];
    char buf[32], *p[9];
    int i;

    uart_init();
    
    while(1)
    {
        puts("
rtc> ");
        gets(buf);
        buf[strlen(buf)-2] = '';
        p[0] = strtok(buf, " ");
        for(i=1; p[i-1]!=NULL; i++)
        {
            p[i] = strtok(NULL, " ");
        }

        if(strcmp(p[0], "timeset") == 0)
        {
            time[0] = atoh(p[1]);
            time[1] = atoh(p[2]);
            time[2] = atoh(p[3]);
            time[3] = atoh(p[4]);
            time[4] = atoh(p[5]);
            time[5] = atoh(p[6]);
            time[6] = atoh(p[7]);
            rtc_init(time);
        }

        if(strcmp(p[0], "time") == 0)
        {
            rtc_display();
        }
    }
}
#endif

#if 1
void niuniu(void)
{
    uart_init();
    int_init();
    alarm_init();
    beeper_init();

    while(1)
    {
        rtc_display();
        sleep(1);
    }
}
#endif

这个是定时器的驱动:

#include "s3c2440.h"

void niuniu(void)
{
    int_init();
    timer_init();
    beeper_init();
    uart_init();

    timer_update();

    while(1)
    {
        puts("haha ......
");
        sleep(1);
    }
}

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

#include "s3c2440.h"
#include <string.h>

#if 0
void niuniu(void)
{
    char buf[32];

    uart_init();

    while(1)
    {
        puts("send: ");
        gets(buf);
        puts("
recv: ");
        puts(buf);
    }
}
#endif

#if 1
void niuniu(void)
{
    char buf[16];
    char *p[6];
    int i;

    beeper_init();
    led_init();
    uart_init();

    while(1)
    {
        puts("
uart> ");
        gets(buf);
        // 去掉

        buf[strlen(buf)-2] = '';
        // strtok函数会使用全局变量
        p[0] = strtok(buf, " ");
        for(i=1; p[i-1]!=NULL; i++)
        {
            p[i] = strtok(NULL, " ");
        }

        if(strcmp(p[0], "ledon") == 0)
        {
            if(strcmp(p[1], "all") == 0)
            {
                for(i=1; i<5; i++)
                {
                    led_on(i);
                }
            }
            else
            {
                for(i=1; p[i]!=NULL; i++)
                {
                    led_on(*p[i]-48);
                }
            }
        }

        if(strcmp(p[0], "ledoff") == 0)
        {
            if(strcmp(p[1], "all") == 0)
            {
                for(i=1; i<5; i++)
                {
                    led_off(i);
                }
            }
            else
            {
                for(i=1; p[i]!=NULL; i++)
                {
                    led_off(*p[i]-48);
                }
            }
        }

        if(strcmp(p[0], "beeperon") == 0)
        {
            beeper_on();
        }

        if(strcmp(p[0], "beeperoff") == 0)
        {
            beeper_off();
        }
    }
}
#endif
原文地址:https://www.cnblogs.com/coding4/p/5603075.html