Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <avr/io.h>
  3. #include <util/delay.h>
  4. #include <string.h>
  5. #include "uart.h"
  6. #include "hmi_msg.h"
  7. #include "../lib/hd44780_111/hd44780.h"
  8.  
  9. #define BLINK_DELAY_MS 1000
  10.  
  11. static inline void init_leds(void)
  12. {
  13.     DDRA |= _BV(DDA4);
  14.     DDRA |= _BV(DDA2);
  15.     DDRA |= _BV(DDA0);
  16.     DDRB |= _BV(DDB7);
  17.     PORTB &= ~_BV(PORTB7);
  18. }
  19.  
  20. /* Init error console as stderr in UART1 and print user code info */
  21. static inline void init_errcon(void)
  22. {
  23.     simple_uart1_init();
  24.     stderr = &simple_uart1_out;
  25.     fprintf(stderr, "Version: %s built on: %s %s\n",
  26.             FW_VERSION, __DATE__, __TIME__);
  27.     fprintf(stderr, "avr-libc version: %s avr-gcc version: %s\n",
  28.             __AVR_LIBC_VERSION_STRING__, __VERSION__);
  29. }
  30.  
  31. static inline void init_stdin(void)
  32. {
  33.   simple_uart0_init();
  34.   stdin = stdout = &simple_uart0_io;
  35. }
  36.  
  37. static inline void blink_leds(void)
  38. {
  39.     while (1) {
  40.         PORTA |= _BV(PORTA0);
  41.         _delay_ms(BLINK_DELAY_MS);
  42.         /*Breakpoint*/
  43.         PORTA &= ~_BV(PORTA0);
  44.         _delay_ms(BLINK_DELAY_MS);
  45.         /*Breakpoint*/
  46.         PORTA |= _BV(PORTA2);
  47.         _delay_ms(BLINK_DELAY_MS);
  48.         /*Breakpoint*/
  49.         PORTA &= ~_BV(PORTA2);
  50.         _delay_ms(BLINK_DELAY_MS);
  51.         /*Breakpoint*/
  52.         PORTA |= _BV(PORTA4);
  53.         _delay_ms(BLINK_DELAY_MS);
  54.         /*Breakpoint*/
  55.         PORTA &= ~_BV(PORTA4);
  56.         _delay_ms(BLINK_DELAY_MS);
  57.         break;
  58.     }
  59. }
  60.  
  61. static inline void init_lcd(void)
  62. {
  63.   lcd_init();
  64.   lcd_home();
  65. }
  66.  
  67. void main(void)
  68. {
  69.   DDRD |= _BV(DDD3);
  70.   init_leds();
  71.   init_errcon();
  72.   fprintf(stdout, "%s\n", myName);
  73.  
  74.   init_lcd();
  75.  
  76.   while(1) {
  77.     blink_leds();
  78.   }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement