中微CMS8S5880 串口输出

废话不多直接上代码

main.c

#include "uart.h"
#include "pwm.h"
#include "led.h"
#include "stdio.h"
#include "sys_time.h"
#include "timer.h"
#include "my_iic.h"



void main()
{
	UART0_INIT();								//initinal UART
	PWM_init();
	LED_INIT();
	Timer2Init();
	set_pwm5_Duty_cycle(30);
	IIC_GPIO_Init();
	printf("code start\r\n");
	EA = 1;//使能总中断
	calc_value_pressure();
	LED4_ON;
	LED5_ON;
	while(1)
	{
		if(get_sys_time_ms() % 100 == 0)
		{
			Put_press_and_temp_value();
			printf("Pressure %f\r\n",pressure);
			printf("TEMP %f\r\n",temp); 
		}
		clrwdt();	
	}

}

lib.h

#ifndef __LIB_H__
#define __LIB_H__

#define BIT0 0x01
#define BIT1 0x02
#define BIT2 0x04
#define BIT3 0x08
#define BIT4 0x10
#define BIT5 0x20
#define BIT6 0x40
#define BIT7 0x80



#endif

uart.c

#include "uart.h"


void uart_puts(uint8_t *ch, uint32_t len)
{    
	if(len > 0)
	{
		uint32_t count = 0;
		while(len)
		{
			SBUF0 =  ch[count++];  
			while (TI0 == 0);
			TI0 = 0;
			len--;	
		}
	}
}

char putchar(char c)
{
    SBUF0 = c;
    while (TI0 == 0);
    TI0 = 0;
    return c;
}


void UART0_INIT()								//BPS
{
    /*P25做TX*/
    P25CFG = 0x02;//详见《用户手册》“端口的复用功能”
    
    /*8位异步模式*/
    SCON0 = 0x40;
	//波特率来源于BRT
    FUNCCR |= 0x05;
    
    //波特率9600,当SysClk=24MHz时
    BRTCON = 0x80;//使能BRT,BRTCKDIV[2:0]=000
    PCON &= 0x7F;//SMOD0=0
    BRTDH = 0xFF;//{BRTDH,BRTDL}=65458,详见《用户手册》第136页
    BRTDL = 0xB2;
    //清标志
    TI0 = 0;
    RI0 = 0;

}

uart.h

#ifndef __USRT_H__
#define __USRT_H__
#include 


void UART0_INIT();								//the BAUD relate the system clock

void uart_puts(uint8_t *ch, uint32_t len);

#endif

 

 

 

你可能感兴趣的:(中微单片机开发,c语言,串口通信,printf,嵌入式,芯片)