完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
`因串口要运行Mon51进行仿真调试,故选一空闲IO模拟串口的TXD信号引脚,硬件为SST89E516,晶振为18.432,12时钟周期的单片机. 相关代码如下: ***it TXD1 = P2^3; //定义模拟输出脚 //***it RXD1 = P1^1; //定义模拟输入脚 bdata unsigned char SBUF1; //定义一个位操作变量 ***it SBUF1_bit0 = SBUF1^0; ***it SBUF1_bit1 = SBUF1^1; ***it SBUF1_bit2 = SBUF1^2; ***it SBUF1_bit3 = SBUF1^3; ***it SBUF1_bit4 = SBUF1^4; ***it SBUF1_bit5 = SBUF1^5; ***it SBUF1_bit6 = SBUF1^6; ***it SBUF1_bit7 = SBUF1^7; bit UART1_RI; #if 1 void delay_bps() { unsigned char data uci; for (uci = 0; uci < 19;uci++); } //波特率9600 /* void delay_Halfbps() { unsigned char data uci; // for (uci = 0; uci < 6;uci++); _nop_();_nop_(); for (uci = 0; uci <50 ;uci++); } //波特率9600 */ #endif #if 0 void delay_bps() { unsigned char data uci; for (uci = 0; uci < 6*9+8;uci++); } //波特率19200 void delay_Halfbps() { unsigned char data uci; for (uci = 0; uci <25 ;uci++); } //波特率19200 #endif //unsigned char getchar2() //从缓冲区内读取一个字节数据 void putchar2(unsigned char input) //向发送缓冲区内写入一个数据 { SBUF1 = input; TXD1 = 0; //起始位 delay_bps(); TXD1 = SBUF1_bit0; //0 delay_bps(); TXD1 = SBUF1_bit1; //1 delay_bps(); TXD1 = SBUF1_bit2; //2 delay_bps(); TXD1 = SBUF1_bit3; //3 delay_bps(); TXD1 = SBUF1_bit4; //4 delay_bps(); TXD1 = SBUF1_bit5; //5 delay_bps(); TXD1 = SBUF1_bit6; //6 delay_bps(); TXD1 = SBUF1_bit7; //7 delay_bps(); TXD1 = 1; //停止位 delay_bps(); } #define SendCharToPrint(x) putchar2(x) void ChangePrintModeToChinese(void) { SendCharToPrint(0x1C); SendCharToPrint(0x26); } void ChangePrintModeToEnglish(void) { SendCharToPrint(0x1C); SendCharToPrint(0x2E); } void PrintFeedPaper(uchar ucLineCount) { SendCharToPrint(0x1B); SendCharToPrint(0x4A); SendCharToPrint(ucLineCount); } void PrintString(uchar *ucString) { uchar ucStringLen; ucStringLen = strlen(ucString); while(ucStringLen--) { SendCharToPrint(*ucString++); } } void TestPrint(void) { ChangePrintModeToChinese(); PrintString("2011年4月3日 21时20分50秒"); } 应用程序中用到的相关代码如下: PrintString("----------------------------"); PrintString(" 智能开关机记录仪启动"); Read_RTC_PCF8563(ucRTCBuff); //将BCD码转换成16进制数据 for(ucCount=0; ucCount<7; ucCount++) { ucTemp = ucRTCBuff[ucCount]; ucRTCBuff[ucCount] = (ucTemp>>4)*10+(ucTemp&0x0F); } sprintf(ucTempBuff,"20%02d年%02d月%02d日 ",(uint)ucRTCBuff[6],(uint)ucRTCBuff[5],(uint)ucRTCBuff[3]); PrintString(ucTempBuff); sprintf(ucTempBuff,"%02d时%02d分%02d秒",(uint)ucRTCBuff[2],(uint)ucRTCBuff[1],(uint)ucRTCBuff[0]); PrintString(ucTempBuff); PrintString("----------------------------"); PrintFeedPaper(50); 效果图如下:
下载 (39.25 KB) 2011-4-3 23:37 还有一段代码如下: //打印当前记录 { uchar ucCount; uchar ucTemp; uchar xdata ucTempBuff[19]; //将BCD码转换成16进制数据 for(ucCount=0; ucCount<7; ucCount++) { ucTemp = ucRTCBuff[ucCount]; ucRTCBuff[ucCount] = (ucTemp>>4)*10+(ucTemp&0x0F); } sprintf(ucTempBuff,"20%02d年%02d月%02d日 ",(uint)ucRTCBuff[6],(uint)ucRTCBuff[5],(uint)ucRTCBuff[3]); PrintString(ucTempBuff); sprintf(ucTempBuff,"%02d时%02d分%02d秒",(uint)ucRTCBuff[2],(uint)ucRTCBuff[1],(uint)ucRTCBuff[0]); PrintString(ucTempBuff); sprintf(ucTempBuff,"通道号:%02d 事件:",(uint)ucRecordNumber); PrintString(ucTempBuff); if(ucActionType == 0) { PrintString("开机"); } else { PrintString("关机"); } PrintString("***********************"); PrintFeedPaper(15); } 效果图如下: |
|
相关推荐
3 个讨论
|
|
同问楼上。。。。关注ing。。。。。
|
|
|
|
|
|
277 浏览 0 评论
【敏矽微ME32G070开发板免费体验】之原厂2812测试例程解析
368 浏览 0 评论
766 浏览 2 评论
《DNESP32S3使用指南-IDF版_V1.6》第二十六章 INFRARED_RECEPTION实验
592 浏览 0 评论
879 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
12039 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 12:38 , Processed in 0.716875 second(s), Total 49, Slave 39 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号