Advertisement
Guest User

Untitled

a guest
Jan 16th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #define F_CPU 7372800UL
  2.  
  3. #include <avr/io.h>
  4. #include <util/delay.h>
  5. #include <stdlib.h>
  6.  
  7. #include "lcd.h"
  8.  
  9. uint8_t kontrast=50;
  10.  
  11. void writeLCD() {
  12. lcd_clrscr();
  13.  
  14. lcd_puts("Mia je best");
  15. }
  16.  
  17. void povecaj() {
  18.  
  19. if(kontrast < 250){
  20. kontrast +=5;
  21. if(kontrast > 100) {
  22. PORTA = 0b00000000;
  23. }
  24. }
  25. OCR1B = kontrast;
  26. }
  27.  
  28. void smanji() {
  29. if(kontrast > 10) {
  30. kontrast -=5;
  31. if (kontrast < 100) {
  32. PORTA = 0b10000000;
  33. }
  34. }
  35. OCR1B = kontrast;
  36. }
  37.  
  38. int main(void) {
  39.  
  40. DDRD = _BV(4);
  41. DDRA = 0xff;
  42. PORTB = _BV(1) | _BV(2);
  43. DDRB = 0xff;
  44.  
  45. TCCR1A = _BV(COM1B1) | _BV(WGM10);
  46. TCCR1B = _BV(WGM12) | _BV(CS11);
  47. OCR1B = kontrast;
  48.  
  49. lcd_init(LCD_DISP_ON);
  50.  
  51. while(1){
  52. if(bit_is_clear(PINB, 1)){
  53. povecaj();
  54. }
  55. if(bit_is_clear(PINB, 2)) {
  56. smanji();
  57. }
  58.  
  59. _delay_ms(150);
  60. writeLCD();
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement