中微CMS8S5880 LED灯点亮

废话不多直接上代码

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

led.c

#include "led.h"
#include <CMS/CMS8S5880.H>
#include "lib.h"

void LED_INIT(void)
{
	P04CFG = 0x00;//GPIO
	P05CFG = 0x00;
	
	P0TRIS	|=	(BIT4 | BIT5);						//输出设置
	P0UP	&=	~(BIT4 | BIT5);						//上拉电阻	
	P0RD	&=	~(BIT4 | BIT5);						//下拉电阻	
	P0OD	&=	~(BIT4 | BIT5);						//推挽输出

	LED4_OFF;
	LED5_OFF;
}

led.h 

#ifndef __LED_H__
#define __LED_H__

#define LED4_ON   P0_4 = 0
#define LED4_OFF  P0_4 = 1

#define LED5_ON   P0_5 = 0
#define LED5_OFF  P0_5 = 1

void LED_INIT(void);

#endif

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值