调试通过的模拟串口及打印机驱动程序
时间:10-02
整理:3721RD
点击:
因串口要运行Mon51进行仿真调试,故选一空闲IO模拟串口的TXD信号引脚,硬件为SST89E516,晶振为18.432,12时钟周期的单片机.
相关代码如下:
sbit TXD1 = P2^3; //定义模拟输出脚
//sbit RXD1 = P1^1; //定义模拟输入脚
bdata unsigned char SBUF1; //定义一个位操作变量
sbit SBUF1_bit0 = SBUF1^0;
sbit SBUF1_bit1 = SBUF1^1;
sbit SBUF1_bit2 = SBUF1^2;
sbit SBUF1_bit3 = SBUF1^3;
sbit SBUF1_bit4 = SBUF1^4;
sbit SBUF1_bit5 = SBUF1^5;
sbit SBUF1_bit6 = SBUF1^6;
sbit 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);
}
效果图如下:
相关代码如下:
sbit TXD1 = P2^3; //定义模拟输出脚
//sbit RXD1 = P1^1; //定义模拟输入脚
bdata unsigned char SBUF1; //定义一个位操作变量
sbit SBUF1_bit0 = SBUF1^0;
sbit SBUF1_bit1 = SBUF1^1;
sbit SBUF1_bit2 = SBUF1^2;
sbit SBUF1_bit3 = SBUF1^3;
sbit SBUF1_bit4 = SBUF1^4;
sbit SBUF1_bit5 = SBUF1^5;
sbit SBUF1_bit6 = SBUF1^6;
sbit 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);
}
效果图如下:
LZ用的打印机是什么型号的?
同问楼上。关注ing。
谢谢分享!