Advertisement
uwezi

labb_03_code_01.c

Nov 13th, 2019
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. /*
  2. ATmega8, 48, 88, 168, 328
  3.  
  4. /Reset PC6|1   28|PC5
  5.        PD0|2   27|PC4
  6.        PD1|3   26|PC3       LCD_RW ( 6)
  7.        PD2|4   25|PC2       LCD_E  ( 5)
  8.        PD3|5   24|PC1       LCD_RS ( 3)
  9.        PD4|6   23|PC0
  10.        Vcc|7   22|Gnd
  11.        Gnd|8   21|Aref
  12.        PB6|9   20|AVcc
  13.        PB7|10  19|PB5 SCK   LCD_D7 (13)
  14.        PD5|11  18|PB4 MISO  LCD_D6 (14)
  15.        PD6|12  17|PB3 MOSI  LCD_D5 (11)
  16.        PD7|13  16|PB2       LCD_D4 (12)
  17.        PB0|14  15|PB1
  18. */
  19.  
  20. #define F_CPU 1000000UL  // 1 MHz standard clock
  21.  
  22. #include <avr/io.h>
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <util/delay.h>
  26. #include "lcd.h"
  27.  
  28. /*
  29.   lcd_printbinary(arg, bits);
  30.   prints a binary number on the LCD
  31.    - arg  unsigned integer value to be printed
  32.    - bits number of bits to be printed, leading zeros are printed
  33. */  
  34.  
  35. void lcd_printbinary(uintmax_t arg, uint8_t bits)
  36. {
  37.   int8_t i=bits;
  38.   while (i>0)
  39.   {
  40.     i--;
  41.     if (arg & (1 << i))
  42.     {
  43.       lcd_putc('1');
  44.     }
  45.     else
  46.     {
  47.       lcd_putc('0');
  48.     }
  49.   }
  50. }
  51.  
  52. int main(void)
  53. {
  54.   lcd_init(LCD_DISP_ON); // initialize LCD
  55.   lcd_clrscr();          // clear screen
  56.  
  57.   DDRD  = 0;             // all pins input on port D
  58.   PORTD = 0xff;          // all pull-ups active on port D
  59.  
  60.   while (1)
  61.   {
  62.     _delay_ms(2);             // short delay
  63.     lcd_gotoxy(0,0);          // start at upper left corner
  64.     lcd_puts("0b");           // leading C-style identifier
  65.     lcd_printbinary(PIND, 8); // print value of PIND
  66.   }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement