main.c
来自「飞思卡尔mc9s12dg128的串口通讯程序,可像串口发送helloworld」· C语言 代码 · 共 83 行
C
83 行
/**************************************************/
/****该程序来自于智能车制作WWW.INTELLIGENTCAR.CN***/
/****************程序问题请与作者联系**************/
/**********BY DEMON EMALI:WANGPANBAO@126.COM*******/
/**************************************************/
#include <hidef.h>
#include <mc9s12dg128.h>
#pragma LINK_INFO DERIVATIVE "mc9s12dg128b"
//char test[10];
unsigned char n[]={'h','e','l','l','o',' ','w','o','r','l','d','!','!','!',' '};
/*-------串口初始化----------------------*/
void SciInit(){
SCI0BDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
SCI0CR1=0; /*normal,no parity*/
SCI0CR2=0X2C; /*RIE=1,TE=1,RE=1*/
}
/*-------发射端程序----------------------*/
void SciTx(unsigned char text){
while (!(SCI0SR1&0x80)); /* wait for output buffer empty */
SCI0DRH=0;
SCI0DRL=text;
}
void main()
{ int i,j;
PORTB=0x00;
DDRB=0xFF;
SciInit();
while(1)
{
PORTB=0x7e;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0xbd;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0xdb;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0xe7;
for(i=0;i<100;i++)
for(j=0;j<1000;j++); //PORTB小灯移动闪烁(向内侧移动)
for(i=0;i<15;i++)
{
SciTx(n[i]); //向串口发送HELLO WORLD
}
PORTB=0xe7;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0xdb;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0xbd;
for(i=0;i<100;i++)
for(j=0;j<1000;j++);
PORTB=0x7e;
for(i=0;i<100;i++)
for(j=0;j<1000;j++); //PORTB小灯移动闪烁 (向外侧移动)
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?