串口

 

#include "usart.h"

void SendByte(u8 byte) 
{
    while(!TXIF)    /* set when register is empty */
        continue;
    TXREG = byte;
}
//把数据转换为文本格式
void SendText(unsigned int byte) 
{    unsigned char k1,k2,k3,k4;

    k1 = byte/1000;
    k2 = byte%1000/100;
    k3 = byte%100/10;
    k4 = byte%10;

    SendByte(k1+0x30);
    SendByte(k2+0x30);
    SendByte(k3+0x30);
    SendByte(k4+0x30);
    SendByte(32); //space key 's ASCII
}
void SendString(u8 *s) 
{
    while(*s!='\0')// \0 表示字符串结束标志,
    {
        SendByte(*s);
        s++;
    }
}

 

 

void main()
{
    u16 ad0,ad1;
    init_comms();
    init_adc(0);
    init_adc(1);
    while(1)
    {    
        ad0 = read_adc(0);
        ad1 = read_adc(1);
        SendString("ad0 = ");SendText(ad0);SendString("\r\n");// “\r\n”是换行符
        SendString("ad1 = ");SendText(ad1);SendString("\r\n");
        SendString("*************************** ");SendString("\r\n");
        delay_100ms(50);
    }
}

 

posted on 2017-02-16 16:59  liushao  阅读(278)  评论(0编辑  收藏  举报

导航