历史上的今天
今天是:2024年11月27日(星期三)
2019年11月27日 | 串口控制FL2440(S3C2440)的LED
2019-11-27 来源:eefocus
开发板:FL2440
芯片:S3C2440
功能:程序运行时点亮一个LED,然后利用PC机通过串口发送一个数,开发板读到这个数后点亮另外一个LED。最基本的串口控制。
代码:
Init.s
AREA |DATA|,CODE,READONLY
ENTRY
ldr r13, =0x1000
IMPORT WuqiMain
b WuqiMain
END
include.h
1 #define rUTRSTAT0 (*(volatile unsigned *)0x50000010) //UART 0 Tx/Rx status
2 #define rULCON0 (*(volatile unsigned *)0x50000000) //UART 0 Line control
3 #define rUCON0 (*(volatile unsigned *)0x50000004) //UART 0 Control
4 #define rUFCON0 (*(volatile unsigned *)0x50000008) //UART 0 FIFO control
5 #define rUBRDIV0 (*(volatile unsigned *)0x50000028) //UART 0 Baud rate divisor
6 #define WrUTXH0(ch) (*(volatile unsigned char *)0x50000020)=(unsigned char)(ch)
7 #define RdURXH0() (*(volatile unsigned char *)0x50000027)
8 #define rURXH0 (*(volatile unsigned *)0X50000024)
9 #define rUTXH0 (*(volatile unsigned *)0X50000020)
10 #define rURXH0 (*(volatile unsigned *)0X50000024)
11
12 #define GPBCON (*(volatile unsigned *)0x56000010)
13 #define GPBDAT (*(volatile unsigned *)0x56000014)
14 #define GPBUP (*(volatile unsigned *)0x56000018)
15
16 #define uchar unsigned char
17 #define uint unsigned int
18 #define U32 unsigned int
19 #define U16 unsigned short
20 #define S32 int
21 #define S16 short int
22 #define U8 unsigned char
23 #define S8 char
24
25 #define TRUE 1
26 #define FALSE 0
27
28 #define OK 1
29 #define FAIL 0
30
31 #define ESC_KEY 0x1b
uart.h
1 #include "include.h"
2 #include 3 4 5 6 void Uart_Init(int baud) 7 { 8 int i; 9 rUFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable 10 11 12 //UART0 13 rULCON0 &=0XFFFFFF00; 14 rULCON0 |=0X03; //1位起始位,8位数据位 15 rUCON0 =0X0805; //串口时钟PCLK,查询方式 16 rUBRDIV0 =0X1A; 17 for(i=0;i<100;i++); 18 } 19 20 21 22 //===================================================================== 23 void Uart_SendByte(int data) 24 { 25 26 if(data=='n') 27 { 28 while(!(rUTRSTAT0 & 0x2)); 29 // Delay(1); //because the slow response of hyper_terminal 30 WrUTXH0('r'); 31 } 32 while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty. 33 // Delay(1); 34 WrUTXH0(data); 35 36 37 } 38 39 //==================================================================== 40 void Uart_SendString(S8 *pt) 41 { 42 while(*pt) 43 Uart_SendByte(*pt++); 44 } 45 46 //===================================================================== 47 //If you don't use vsprintf(), the code size is reduced very much. 48 void Uart_Printf(S8 *fmt,...) 49 { 50 va_list ap; 51 S8 str[255]; 52 53 va_start(ap,fmt); 54 vsprintf(str,fmt,ap); 55 Uart_SendString(str); 56 va_end(ap); 57 } 58 59 //===================================================================== 60 61 /* 62 char Uart_GetKey(void) 63 { 64 65 if(rUTRSTAT0 & 0x1) //Receive data ready 66 return rURXH0 ; 67 else 68 return 0; 69 70 } 71 */ main.c #include"include.h" #include "uart.h" void Delay(int count) { unsigned int i; while (--count != 0) { for (i=0; i<255; i++); // ";" 表示空语句,CPU空转。 } } void WuqiMain(void) { char buf; GPBUP = 0x00; GPBCON &= ~(1<<13); GPBCON |= (1<<12); GPBCON &= ~(1<<21); GPBCON |= (1<<20); while(1) { GPBDAT &= ~(1<<6); GPBDAT &= 0xffe; if(rUTRSTAT0 & 0X01) //接收是否完毕 =1结束 { buf=rURXH0; //读取数据 while(!(rUTRSTAT0 & 0X04));//是否允许发送 =1允许 rUTXH0=buf; } if(buf=='1') { GPBDAT &= ~(1<<10); } } } 测试一下,vc6,file——new——projects——win32consoleApplication——a simple application 1 #include "stdafx.h" 2 #include 3 #include 4 5 6 int main(int argc, char* argv[]) 7 { 8 char lpBuf[]="1"; 9 FILE * pFile=fopen("COM1","w"); 10 if(pFile==NULL) 11 { 12 return 1; 13 } 14 fwrite(lpBuf,sizeof(char),strlen(lpBuf),pFile); 15 fclose(pFile); 16 return 0; 运行后开发板两个LED亮,也可用串口调试助手发送“1”来测试。
史海拾趣
|
逻辑分析仪是利用时钟从测试设备上采集和显示数字信号的仪器,最主要作用在于时序判定。由于逻辑分析仪不像示波器那样有许多电压等级,通常只显示两个电压(逻辑1和0),因此设定了参考电压后,逻辑分析仪将被测信号通过比较器进行判定,高于参考电 ...… 查看全部问答> |
|
TMS320C6713 芯片只有20根地址线EA[21:2],问题1:怎么手册(sprs186l.pdf)上说能够“512M-Byte Total Addressable ExternalMemory Space”?问题2:在第16页的“ TMS320C6713 Memory Map Summary” 提到的地址,例如: ---------- ...… 查看全部问答> |
|
请问如何,控制步进电机的步数(例如一次走50步,或是走90度) C语言 #include #define OUTPUT P1 unsigned char steps=1; unsigned char times=10; int j=0; char excite[]={0x01,0x02,0x04,0x08}; void step_rst(void); void delay50ms(int); main() { ...… 查看全部问答> |
|
通过何种方式可以轻松实现计算机-继电器(或者PLC)简单的通讯控制 需要实现简单1/0通讯,计算机得到继电器开关信号,同时通过判断返回一个开关信号到继电器。 是否需要串口通讯?和其他更简单办法?请不吝赐教。 … 查看全部问答> |
|
*/linking... *** ERROR L107: ADDRESS SPACE OVERFLOW SPACE: HCONST SEGMENT: ?FC?OVTFONT_4_CE_D7 LENGTH: 0076F8H *** ERROR L120: CONTENT BELONGS TO ERRONEOUS SEGMEN ...… 查看全部问答> |
|
PIC16F1937驱动LCD,怎么也不亮,这是我的程序初始化LCD的代码,当然那些I/O口的也设置了,我像随便点亮下,他就是不亮了,很久没有玩汇编代码了,搞了好久,搞不对!LCD_RET BANKSEL LCDPS&nbs ...… 查看全部问答> |




