芯圣SQ013单片机 ,是一颗8位精简指令集单片机,支持C语言,汇编编程,但由于没有硬件UART,所以我们采用IO口进行模拟。
程序代码
#include "holychip_define.h"
#define TXD PORTB1
//#define RXD PORTB4
unsigned int Count=0;
unsigned int Time_1s;
unsigned int i ;
void Delay(unsigned char i)
{
while(i--);
}
/*------------------------------------------------
mS延时函数,含有输入参数 unsigned int t,无返回值
unsigned int 是定义无符号字符变量,其值的范围是
0~1024 精确延时请使用汇编
-------------------------------------------------*/
void DelayMS(unsigned int t)
{
unsigned char count = 195;
while(t--)
{
while(count--);
}
}
void Init(void)
{
PORTB = 0B00110010; //PB1上电高电平
TRISB = 0X00;
PHCON = 0XFF;
PDCON = 0xff;
ODCON = 0X00;
}
void Time0_Init(void)
{
OPTION = 0x16;
T0 = 178; //定时50ms
T0IE = 1;
T0IF = 0;
GIE = 1;
}
void WriteByte(unsigned char Byte)
{
unsigned char i = 8;
TXD = 0; //发送起始位
Delay(25);
//发送8位数据位
while(i--)
{
TXD = (Byte&0x01); //先传最低位
Byte = Byte>>1;
Delay(25);
}
//发送校验位
TXD = 1;
Delay(25);
}
void UART_SendString(unsigned char *buf)
{
while(*buf!='\0')
{
WriteByte(*buf);
buf++;
}
}
void main(void)
{
unsigned int i ;
Init();
Time0_Init();
while(1)
{
if(Time_1s==1)
{
Time_1s=0;
for(i=0;i<3;i++)
{
UART_SendString("Hello,World!");
DelayMS(1);
}
asm(sleep);asm(nop);asm(nop);asm(nop);
}
}
}
//*****************************中断服务程序*****************************
//进中断时间=1/(时钟源/xT/分频比)*(256-T0初值)
void Intr(void) __interrupt 0
{
if(T0IF)
{
T0IF =0;
T0 = 178;
Count++;
if(Count>=200)
{
Count=0;
Time_1s=1; //1s时间到
}
}
}
原文链接:https://blog.csdn.net/impressively/article/details/106694236
|