找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 1778|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

求指導(dǎo)ARM Cortex A9 實(shí)驗(yàn),按鍵計(jì)數(shù)器和串口終端命令控制器,根據(jù)給的代碼

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1044331 發(fā)表于 2023-4-1 16:07 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
50黑幣
一:按鍵計(jì)數(shù)器。
將四個(gè)LED作為二進(jìn)制輸出,按鍵中斷K2作為累加計(jì)數(shù),每按下一下,LED二進(jìn)制數(shù)加一,按鍵中斷K3作為累減計(jì)數(shù),每按下一下,LED二進(jìn)制數(shù)減一,并將結(jié)果通過(guò)串口終端輸出顯示。在此基礎(chǔ)上,可以進(jìn)一步融合構(gòu)思其它控制功能。
#include "exynos_4412.h"
static int num = 0;
/**********************************************************************
* @brief     IRQ Interrupt Service Routine program body
* @param[in] None
* @return        None
**********************************************************************/
void do_irq(void )
{
    int irq_num;
    irq_num = (CPU0.ICCIAR & 0x3FF);
    switch (irq_num) {
    case 58: //turn on LED2;turn off LED3
       GPX2.GPX2DAT = 0x1 << 7;
       GPX1.GPX1DAT &= ~0x1;
       printf("IRQinterrupt !! turn on LED2; turn off LED3\n");
       //Clear Pend
       EXT_INT41_PEND|= 0x1 << 2;
       ICDICPR.ICDICPR1 |= 0x1 <<26;
       break;
    case 57: //Turn on Led3;Turn off Led2
       GPX2.GPX2DAT &= ~(0x1<< 7);
       GPX1.GPX1DAT |= 0x1;
       printf("IRQinterrupt !! Turn on LED3; Turn off LED2\n");
       //Clear Pend
       EXT_INT41_PEND |= 0x1 << 1;
       ICDICPR.ICDICPR1 |= 0x1 <<26;
       break;
    }
    // End ofinterrupt
    CPU0.ICCEOIR = (CPU0.ICCEOIR & ~(0x1FF)) |irq_num;
}
void mydelay_ms(int ms)
{
    int i, j;
    while(ms--)
    {
       for (i = 0; i < 5;i++)
           for (j = 0; j <514; j++);
    }
}
int main(void)
{
    //LED2 GPX2_7
    GPX2.GPX2CON |= 0x1 <<28;
    //LED3 GPX1_0
    GPX1.GPX1CON |= 0x1;
    //Led4 GPF3_4
    GPF3.GPF3CON |= 0x1 <<16;
    //Key_2  Interrupt GPX1_1
    GPX1.GPX1PUD = GPX1.GPX1PUD & ~(0x3<< 2); // Disables Pull-up/Pull-down
    GPX1.GPX1CON = (GPX1.GPX1CON & ~(0xF<< 4)) | (0xF << 4); //GPX1_1: WAKEUP_INT1[1](EXT_INT41[1])
    EXT_INT41_CON =(EXT_INT41_CON & ~(0x7 << 4)) | 0x2 << 4;
    EXT_INT41_MASK =(EXT_INT41_MASK & ~(0x1 << 1)); // Bit: 1 = Enables interrupt
    //Key_3  Interrupt GPX1_2
    GPX1.GPX1PUD = GPX1.GPX1PUD & ~(0x3<< 4); // Disables Pull-up/Pull-down
    GPX1.GPX1CON = (GPX1.GPX1CON & ~(0xF<< 8)) | (0xF << 8); //GPX1_2:WAKEUP_INT1[2] (EXT_INT41[2])
    EXT_INT41_CON =(EXT_INT41_CON & ~(0x7 << 8)) | 0x2 << 8;
    EXT_INT41_MASK =(EXT_INT41_MASK & ~(0x1 << 2)); // Bit: 1 = Enables interrupt
    /*
     * GIC interrupt controller:
     * */
    // Enables thecorresponding interrupt SPI25, SPI26 -- Key_2, Key_3
    ICDISER.ICDISER1 |= (0x1 <<25) | (0x1 << 26);
    CPU0.ICCICR |= 0x1; //Global enablefor signaling of interrupts
    CPU0.ICCPMR = 0xFF; //The prioritymask level.Priority filter. threshold
    ICDDCR = 1;   //Bit1:  GICmonitors the peripheral interrupt signals and
                  //     forwards pending interrupts to the CPUinterfaces2
    ICDIPTR.ICDIPTR14 = 0x01010101; //SPI25  SPI26  interrupts are sent to processor 0
    printf("\n********* GIC test ********\n");
    while (1){
       GPF3.GPF3DAT |= 0x1 << 4;
       mydelay_ms(500);
       GPF3.GPF3DAT &= ~(0x1<< 4);
       mydelay_ms(500);
    }
    return 0;

}


二:串口終端命令控制器
通過(guò)串口終端輸入來(lái)控制LED,
當(dāng)串口輸入”A”,回車,第1個(gè)LED亮,其它滅;
當(dāng)串口輸入”B”, 回車,第2個(gè)LED亮,其它滅;
當(dāng)串口輸入”C”, 回車, 第3個(gè)LED亮,其它滅;
當(dāng)串口輸入”C”, 回車,第4個(gè)LED亮,其它滅;
當(dāng)串口輸入”LEFT”, 回車,4個(gè)LED實(shí)現(xiàn)左流水燈;
當(dāng)串口輸入”RIGHT”, 回車,4個(gè)LED實(shí)現(xiàn)右流水燈;
在此基礎(chǔ)上,可以進(jìn)一步融合構(gòu)思其它控制功能。
#include "exynos_4412.h"
void mydelay_ms(int time)
{
    int i, j;
    while(time--)
    {
       for (i = 0; i < 5; i++)
           for (j = 0; j < 514; j++);
    }
}
void uart_init(void)
{
    /*UART2 initialize*/
    GPA1.GPA1CON = (GPA1.GPA1CON & ~0xFF ) | (0x22); //GPA1_0:RX;GPA1_1:TX
    UART2.ULCON2 = 0x3; //Normal mode, Noparity,One stop bit,8 data bits
    UART2.UCON2 = 0x5;  //Interrupt request or polling mode
    /*
     * Baud-rate 115200:src_clock:100Mhz
     * DIV_VAL = (100*10^6 /(115200*16) -1) = (54.3 - 1) = 53.3
     * UBRDIV2 = (Integer partof 53.3) = 53 = 0x35
     * UFRACVAL2 = 0.3*16 = 0x5
     * */
    UART2.UBRDIV2 = 0x35;
    UART2.UFRACVAL2 = 0x5;
}
void putc(const char data)
{
    while(!(UART2.UTRSTAT2 & 0X2));
    UART2.UTXH2 = data;
    if (data == '\n')
           putc('\r');
}
void puts(const  char  *pstr)
{
    while(*pstr != '\0')
       putc(*pstr++);
}
unsigned char getchar()
{
    unsigned char c;
    while(!(UART2.UTRSTAT2 & 0X1));
    c = UART2.URXH2;
    return c;
}
int main(void) {
    char c, str[] = "uarttest!! \n";
    //LED
    GPX2.GPX2CON = 0x1 << 28;
    uart_init();
    while(1)
       {
           //Turn on LED
           GPX2.GPX2DAT = GPX2.GPX2DAT | 0x1 << 7;
           puts(str);
           mydelay_ms(500);
           //Turn off LED
           GPX2.GPX2DAT = GPX2.GPX2DAT & ~(0x1 << 7);
           mydelay_ms(500);
       }
    return 0;

}

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:1044331 發(fā)表于 2023-4-1 16:39 | 只看該作者
用的是Eclipse,串口不能用getchar
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表