這些範例是早期我在資策會帶一些嵌入式課程時,所完成的範例,那時候是使用 uCLinux 作業系統,而這些範例均適用於我以前所作的兩片開發板:W90N745 與 W90N740(ARMax) 教學開發板。我在上課時,先從線路講解給學員了解後,再依照使用到的 IC 與 CPU 說明其規格(就是要依照線路及規格撰寫韌體),最後再講解為什麼要如此寫這些CODE,才能讓 ARM 板依照我們所講的功能動作。當然在 ARM7 CPU 上的 uCLinux 上沒有 MMU 單元,SO...AP 程式可以直接存取 IC/CPU 硬體上對應的記憶體位址,這些範例就如此形成,一般來說,Embedded Linux 最後尚需再將這些範例包裝成 Embedded Linux 驅動程式結構。
W90N745 教學開發板:
W90N740(ARMax) 教學開發板:
這些範例計有:1. LED顯示範例、2.Key 按鍵輸入範例、3.GPIO 測試範例、4.Uart 驅動範例、5.LCD驅動範例、6.audio音效驅動範例、7.Socket 程式範例,及 Web Server ( BoA )+CGI 移植。這些程式範例,請搭配 W90N745 與 W90N740(ARMax) 教學開發板 的線路圖。
這些程式碼如下:
1. LED顯示範例:
2.Key 按鍵輸入範例:
3.GPIO 測試範例
/*
* GPIO 8 Example for ARM-W90N745
* Copyright (C) 2006~2008 Yi-Hua, Chiang
* microcyh@seed.net.tw
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int a;
volatile unsigned int regGPIO_CFG5, regGPIO_DIR5, regGPIO_DATAOUT5;
regGPIO_CFG5 = *((volatile unsigned int*)0xFFF83050);
regGPIO_CFG5 = regGPIO_CFG5 & 0xFFFFFF3F; // bit[7..6] 00 = GPIO8 I/O
*((volatile unsigned int*)0xFFF83050) = regGPIO_CFG5;
regGPIO_DIR5 = *((volatile unsigned int*)0xFFF83054); //
regGPIO_DIR5 = regGPIO_DIR5 | 0x80008;//0000 0000 0000 1000 0000 0000 0000 1000
*((volatile unsigned int*)0xFFF83054) = regGPIO_DIR5;
regGPIO_DATAOUT5 = *((volatile unsigned int*)0xFFF83058);
for( a=1; a <=10; a++ )
{
regGPIO_DATAOUT5 = regGPIO_DATAOUT5 | 0x8;
*((volatile unsigned int*)0xFFF83058) = regGPIO_DATAOUT5;
sleep(1);
regGPIO_DATAOUT5 = regGPIO_DATAOUT5 & 0xFFFFFFF7;
*((volatile unsigned int*)0xFFF83058) = regGPIO_DATAOUT5;
sleep(1);
}
return 0;
}
4.Uart poll 驅動範例:
/*
* Uart poll Example for ARM-W90N745
* Copyright (C) 2006~2008 Yi-Hua, Chiang
* microcyh@seed.net.tw
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i=0;
volatile unsigned char regUART0_LSR, regUART0_RBR;
char showStr[] = "Hello CYH", showChar;
char *Mess;
/*Program Function:
1. print : Hello CYH
2. print : please input your name
3. get : ...[enter]
4. print : Hello your_name
5. print : please input a message[q/Q exit]
6. get : ...[enter]
*/
while( (showChar = showStr[i++]) != '\0' )
{
while( ((regUART0_LSR = *((volatile unsigned char*)0xFFF80014)) & 0x20 ) != 0x20 )
;
*((volatile unsigned char*)0xFFF80000) = showChar;
}
while( ((regUART0_LSR = *((volatile unsigned char*)0xFFF80014)) & 0x20 ) != 0x20 )
;
*((volatile unsigned char*)0xFFF80000) = '\n';
Mess = (char *)malloc( 100 );
i = 0;
while( regUART0_RBR != 13 ) // enter
{
while( ((regUART0_LSR = *((volatile unsigned char*)0xFFF80014)) & 0x01 ) == 0x00 )
;
regUART0_RBR = *((volatile unsigned char*)0xFFF80000);
Mess[ i++ ] = regUART0_RBR;
}
i = 0;
while( (showChar = Mess[i++]) != '\0' )
{
while( ((regUART0_LSR = *((volatile unsigned char*)0xFFF80014)) & 0x20 ) != 0x20 )
;
*((volatile unsigned char*)0xFFF80000) = showChar;
}
while( ((regUART0_LSR = *((volatile unsigned char*)0xFFF80014)) & 0x20 ) != 0x20 )
;
*((volatile unsigned char*)0xFFF80000) = '\n';
return 0;
}
5.LCD驅動範例:
/*
* EBILCD Example for ARM-W90N745
* Copyright (C) 2006~2008 Yi-Hua, Chiang
* microcyh@seed.net.tw
*/
#include <stdio.h>
#include "wblib.h"
#define EBIBase 0x8000000
void initLCD();
void LCDComm( unsigned char data );
void LCDData( unsigned char data );
void delay( int x1 )
{ int n1;
for( n1=0; n1<=x1; n1++ )
;
}
int main()
{ int n1;
unsigned int regCLKSEL;
unsigned char *ShowStr = "Hello microcyh",*ShowStr2 = "Hello YiHua, Chiang", ShowChar;
regCLKSEL = *((volatile unsigned int *)(0xFFF0000C));
regCLKSEL = (regCLKSEL & 0xFFFFFFF1) | 0x2; // 001
*((volatile unsigned int *)(0xFFF0000C)) = regCLKSEL;
usleep( 2000 );
// 先關閉 Catch
*((volatile unsigned int *)(0xFFF02000)) = 0;
EBI_IOTiming2(EXT1, 0x7 , 0x7 );
EBI_IOTiming1(EXT1, 0xF, 0x7 );
EBI_IOSetup( EXT1 , 0x8000000 , SIZE_256K , BUS_BIT_8 ); // wb_ebi.c
initLCD();
LCDComm( 0x80 );//Set DDRAM Address 由第一行第一個字 開始 show
while( (ShowChar = *ShowStr) != '\0' )
{
LCDData( ShowChar);
ShowStr = ShowStr + 1;
}
LCDComm( 0x80+0x40 );//Set DDRAM Address 由第 2 行第一個字 開始 show
while( (ShowChar = *ShowStr2) != '\0' )
{
LCDData( ShowChar);
ShowStr2 = ShowStr2 + 1;
}
return 0;
}
void initLCD()
{
LCDComm( 0x01 );// clear Display
usleep( 2000 );
LCDComm( 0x08 );//OFF Display ON/OFF
usleep( 1 );
LCDComm( 0x38 );//Function Set 0 0 1 1 N F X X N 0 1-line mode 1 2-line mode F 0 display off 1 display on
usleep( 1 );
LCDComm( 0x80 );//Set DDRAM Address 由第一行第一個字 開始 show
usleep( 1 );
LCDComm( 0x0c );//Display ON/OFF Control 0000 1DCB-->D0 display off 1 display on C 0 cursor off 1 cursor on B 0 blink off 1 blink on
usleep( 1 );
LCDComm( 0x06 );//Entry Mode Set 0000 01 I/D SH-->I/D 0 decrement mode 1 increment mode SH 0 entire shift off 1 entire shift on
usleep( 1 );
}
void LCDComm( unsigned char data )
{
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x00 | 0x08;
usleep( 1 ); // 1us = 1000 ns
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x04 | 0x08;
usleep( 1 );
*((volatile unsigned char *)(0x8000000 + 0xE00 )) = data; // data
usleep( 1 );
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x00 | 0x08;
}
void LCDData( unsigned char data )
{
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x02 | 0x08;
delay( 10 );//usleep( 1 ); // 1us = 1000 ns
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x06 | 0x08;
delay( 10 );//usleep( 1 );
*((volatile unsigned char *)(0x8000000 + 0xE00 )) = data; // data
delay( 10 );//usleep( 1 );
*((volatile unsigned char *)(0x8000000 + 0xF00 )) = 0x02 | 0x08;
}
6.audio音效驅動範例:
7.Socket 程式範例:
沒有留言:
張貼留言