MM32F103 数码管动态驱动演示
<div class='showpostmsg'> 本帖最后由 serialworld 于 2018-11-1 06:29 编辑MM32F103 数码管动态驱动演示,比较简单,就不多解释了。另外测试了一下96Mhz单片机全速运行的电流,5V时13.5mA左右,3.3V时使用万用表无法测量,应该是表笔的干扰较大,单片机无法正常启动。
#include "delay.h"
#include "sys.h"
#include "led.h"
#include "key.h"
#include"uart.h"
#include "uart_nvic.h"
#include <stdio.h>
#include <unistd.h>
void LED_display(uint16_t data);
void LED_c(uint16_t data);
void LED_4(void);
void LED_5(void);
void LED_6(void);
uint8_t LED_buffer = { 0xa1 };
int _write(int32_t fd, char* ptr, int32_t len) {
if (fd == STDOUT_FILENO || fd == STDERR_FILENO) {
int32_t i = 0;
while (i < len) {
while (UART_GetFlagStatus(UART1, UART_IT_TXIEN) == RESET)
;
UART_SendData(UART1, (uint8_t) ptr);
}
}
return len;
}
uint16_t dis_buffer = { 0 };
int main(void) {
u8 t = 0;
u8 len;
u16 times = 0;
delay_init(); //延时函数初始化
LED_Init(); //初始化与LED连接的硬件接口
// KEY_Init(); //初始化与按键连接的硬件接口
LED2 = 0; //点亮LED
// uart_initwBaudRate(115200u);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 设置中断优先级分组2
uart_nvic_init(115200); //串口初始化为115200
while (1) {
// t=KEY_Scan(0); //得到键值
if (UART_RX_STA & 0x8000) {
len = UART_RX_STA & 0x3fff; //得到此次接收到的数据长度
printf("\r\n your message is \r\n");
for (t = 0; t < len; t++) {
while (UART_GetFlagStatus(UART1, UART_IT_TXIEN) == RESET)
;
UART_SendData(UART1, (u8) UART_RX_BUF);
}
printf("\r\n\r\n"); //插入换行
UART_RX_STA = 0;
} else {
times++;
if (times % 50 == 0) {
printf("\r\n Serial port test\r\n");
dis_buffer = (times / 50) % 10;
dis_buffer = (times / 50) % 10;
dis_buffer = (times / 50) % 10;
dis_buffer = (times / 50) % 10;
// delay_ms(10);
}
if (times % 200 == 0)
printf("please input date\r\n");
if (times % 30 == 0)
LED2 = !LED2; //闪烁LED,提示系统正在运行.
}
LED_4();
// LED_6();
}
}
void LED_display(uint16_t data) {
switch (data) {
case 0:
led_a = !1;
led_b = !1;
led_c = !1;
led_d = !1;
led_e = !1;
led_f = !1;
led_g = !0;
led_dp = !0;
break;
case 1:
led_a = !0;
led_b = !1;
led_c = !1;
led_d = !0;
led_e = !0;
led_f = !0;
led_g = !0;
led_dp = !0;
break;
case 2:
led_a = !1;
led_b = !1;
led_c = !0;
led_d = !1;
led_e = !1;
led_f = !0;
led_g = !1;
led_dp = !0;
break;
case 3:
led_a = !1;
led_b = !1;
led_c = !1;
led_d = !1;
led_e = !0;
led_f = !0;
led_g = !1;
led_dp = !0;
break;
case 4:
led_a = !0;
led_b = !1;
led_c = !1;
led_d = !0;
led_e = !0;
led_f = !1;
led_g = !1;
led_dp = !0;
break;
case 5:
led_a = !1;
led_b = !0;
led_c = !1;
led_d = !1;
led_e = !0;
led_f = !1;
led_g = !1;
led_dp = !0;
break;
case 6:
led_a = !1;
led_b = !0;
led_c = !1;
led_d = !1;
led_e = !1;
led_f = !1;
led_g = !1;
led_dp = !0;
break;
case 7:
led_a = !1;
led_b = !1;
led_c = !1;
led_d = !0;
led_e = !0;
led_f = !0;
led_g = !0;
led_dp = !0;
break;
case 8:
led_a = !1;
led_b = !1;
led_c = !1;
led_d = !1;
led_e = !1;
led_f = !1;
led_g = !1;
led_dp = !0;
break;
case 9:
led_a = !1;
led_b = !1;
led_c = !1;
led_d = !1;
led_e = !0;
led_f = !1;
led_g = !1;
led_dp = !0;
break;
default:
break;
}
return;
}
void LED_c(uint16_t data) {
switch (data) {
case 0:
led_c1 = 0;
led_c2 = 1;
led_c3 = 1;
led_c4 = 1;
break;
case 1:
led_c1 = 1;
led_c2 = 0;
led_c3 = 1;
led_c4 = 1;
break;
case 2:
led_c1 = 1;
led_c2 = 1;
led_c3 = 0;
led_c4 = 1;
break;
case 3:
led_c1 = 1;
led_c2 = 1;
led_c3 = 1;
led_c4 = 0;
break;
default:
led_c1 = 1;
led_c2 = 1;
led_c3 = 1;
led_c4 = 1;
break;
}
return;
}
void LED_4(void) {
uint16_t i;
for (i = 0; i < 4; i++) {
LED_c(i);
LED_display(dis_buffer);
delay_ms(2);
}
// LED_c(i);
return;
}
void LED_5(void) {
int i;
for (i = 0; i < 1; i++) {
led_a = !((LED_buffer >> 0) & 0x01);
delay_ms(2);
led_b = !((LED_buffer >> 1) & 0x01);
delay_ms(2);
led_c = !((LED_buffer >> 2) & 0x01);
delay_ms(2);
led_d = !((LED_buffer >> 3) & 0x01);
delay_ms(2);
led_e = !((LED_buffer >> 4) & 0x01);
delay_ms(2);
led_f = !((LED_buffer >> 5) & 0x01);
delay_ms(2);
led_g = !((LED_buffer >> 6) & 0x01);
delay_ms(2);
}
}
void LED_6(void) {
uint16_t i;
for (i = 0; i < 4; i++) {
LED_c(i);
// LED_display(dis_buffer);
LED_5();
delay_ms(2);
}
// LED_c(i);
return;
}
此内容由EEWORLD论坛网友serialworld原创,如需转载或用于商业用途需征得作者同意并注明出处u
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> {:1_103:}
页:
[1]