This post was last edited by serialworld on 2018-11-1 06:29 The MM32F103 digital tube dynamic drive demonstration is relatively simple, so I won't explain it in detail. In addition, the current of the 96Mhz microcontroller running at full speed was tested. It was about 13.5mA at 5V. It could not be measured with a multimeter at 3.3V. It should be that the interference of the test leads was too large, and the microcontroller could not start normally.
- #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[4] = { 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[i++]); } } return len; } uint16_t dis_buffer[3] = { 0 }; int main(void) { u8 t = 0; u8 len; u16 times = 0; delay_init(); //delay function initialization LED_Init(); //initialize the hardware interface connected to the LED // KEY_Init(); //initialize the hardware interface connected to the key LED2 = 0; //Turn on the LED // uart_initwBaudRate(115200u); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //Set interrupt priority group 2 uart_nvic_init(115200); //Initialize the serial port to 115200 while (1) { // t=KEY_Scan(0 ); //Get the key value if (UART_RX_STA & 0x8000) { len = UART_RX_STA & 0x3fff; //Get the length of the data received this time 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[t]); } printf("\r\n\r\n"); //Insert newline UART_RX_STA = 0; } else { times++; if (times % 50 == 0) { printf("\r\n Serial port test\r\n"); dis_buffer[0] = (times / 50) % 10; dis_buffer[1] = (times / 50) % 10; dis_buffer[2] = (times / 50) % 10; dis_buffer[3] = (times / 50) % 10; // delay_ms(10); } if (times % 200 == 0) printf("please input date\r\n"); if (times % 30 == 0) LED2 = !LED2; //Flash LED to indicate that the system is running. } 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[i]);
- delay_ms(2);
- }
- // LED_c(i);
- return;
- }
- void LED_5(void) {
- int i;
- for (i = 0; i < 1; i++) {
- led_a = !((LED_buffer[0] >> 0) & 0x01);
- delay_ms(2);
- led_b = !((LED_buffer[0] >> 1) & 0x01);
- delay_ms(2);
- led_c = !((LED_buffer[0] >> 2) & 0x01);
- delay_ms(2);
- led_d = !((LED_buffer[0] >> 3) & 0x01);
- delay_ms(2);
- led_e = !((LED_buffer[0] >> 4) & 0x01);
- delay_ms(2);
- led_f = !((LED_buffer[0] >> 5) & 0x01);
- delay_ms(2);
- led_g = !((LED_buffer[0] >> 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[i]);
- LED_5();
- delay_ms(2);
- }
- // LED_c(i);
- return;
- }
复制代码
此内容由EEWORLD论坛网友serialworld原创,如需转载或用于商业用途需征得作者同意并注明出处u