|
最近在开发中用到了ST16C2552器件。ST16C2552是用于串行数据通信的2通道通用带16字节收发FIFO的异步收发器(UART)。它的基本功能是将并行数据转换成串行数据,反之亦然。UART可处理高达5Mbit/s的串行数据速率。同时,ST16C2552自带了调制解调器的控制功能,由于我的项目较为简单,没有用到调制解调器功能。
该器件使用起来并不难,硬件只要按资料的标准电路连接就行,需要通信中断功能,则将其中断信号引脚与单片机的外部中断引脚相连,软件方面只要进行好初始化就可以了。
参考代码:
假设器件地址为0x8000,通道A地址为0x8008-0x800F,通道B地址为0x8000-0x8007
#define CHA_RHR (*(unsigned char *)0x8008) /* read only */
#define CHA_THR (*(unsigned char *)0x8008) /* write only */
#define CHA_IER (*(unsigned char *)0x8009) /* write only */
#define CHA_FCR (*(unsigned char *)0x800A) /* write only */
#define CHA_ISR (*(unsigned char *)0x800A) /* read only */
#define CHA_LCR (*(unsigned char *)0x800B) /* write only */
#define CHA_MCR (*(unsigned char *)0x800C) /* write only */
#define CHA_LSR (*(unsigned char *)0x800D) /* read only */
#define CHA_MSR (*(unsigned char *)0x800E) /* read only */
#define CHA_SPR (*(unsigned char *)0x800F) /* read and write */
/* the three register sets are accessible when LCR bit7 is a logic 1 */
#define CHA_DLL (*(unsigned char *)0x8008) /* read and write */
#define CHA_DLM (*(unsigned char *)0x8009) /* read and write */
#define CHA_AFR (*(unsigned char *)0x800A) /* read and write */
#define CHB_RHR (*(unsigned char *)0x8000) /* read only */
#define CHB_THR (*(unsigned char *)0x8000) /* write only */
#define CHB_IER (*(unsigned char *)0x8001) /* write only */
#define CHB_FCR (*(unsigned char *)0x8002) /* write only */
#define CHB_ISR (*(unsigned char *)0x8002) /* read only */
#define CHB_LCR (*(unsigned char *)0x8003) /* write only */
#define CHB_MCR (*(unsigned char *)0x8004) /* write only */
#define CHB_LSR (*(unsigned char *)0x8005) /* read only */
#define CHB_MSR (*(unsigned char *)0x8006) /* read only */
#define CHB_SPR (*(unsigned char *)0x8007) /* read and write */
/* the three register sets are accessible when LCR bit7 is a logic 1 */
#define CHB_DLL (*(unsigned char *)0x8000) /* read and write */
#define CHB_DLM (*(unsigned char *)0x8001) /* read and write */
#define CHB_AFR (*(unsigned char *)0x8002) /* read and write */
CHA_LCR = 0x83;
CHA_DLL = 0x0C; // 1843200/16/9600 = 0x0C,9600BPS
CHA_DLM = 0x00;
CHA_AFR = 0x00;
CHA_LCR = 0x03; // divisor latch disable,access general register
/* to COM B register init */
CHB_LCR = 0x83; // divisor latch enable,access special register
CHB_DLL = 0x0C; // 1843200/16/9600 = 0x0C,9600BPS
CHB_DLM = 0x00;
CHB_AFR = 0x00;
CHB_LCR = 0x03; // divisor latch disable,access general register
由于不使用调制解调器,初始化很简单了,以后只要向CHA_THR或CHA_THR就能发送数据,接收数据则是读CHA_RHR或CHA_RHR
ST16C2552器件资料
点击此处打开ourdev_175503.pdf(文件大小:375K)
SC16C2552与ST16C2552器件兼容
点击此处打开ourdev_175504.pdf(文件大小:502K) |
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|