中微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 <CMS/CMS8S5880.H>


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

void uart_puts(uint8_t *ch, uint32_t len);

#endif

 

 

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值