Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.88 KB | None | 0 0
  1. /*
  2.  * lcd.c
  3.  *
  4.  *  Created on: Nov 4, 2019
  5.  *      Author: Student_CLL
  6.  */
  7.  
  8. #include "lcd.h"
  9.  
  10. void init_lcd()
  11. {
  12.     setPort(&DDRC, 0xff);
  13.     setPort(&DDRB, 0xff);
  14.     for(int i=0;i<4;i++)
  15.         CommandLCD(0x38);
  16.     CommandLCD(0x08);
  17.     CommandLCD(0x01);
  18.     CommandLCD(0x06);
  19.     CommandLCD(0x0E);
  20. }
  21.  
  22. void CommandLCD(uint8_t comm)
  23. {
  24.  
  25.     setPort(&PORTB, 0b00000001);
  26.     _delay_ms(5);
  27.     setPort(&PORTC, comm);
  28.     _delay_ms(5);
  29.     setPort(&PORTB, 0x00);
  30.     _delay_ms(5);
  31. }
  32.  
  33. void WriteLCD(uint8_t caracter)
  34. {
  35.     setPort(&PORTB, 0b00000011);
  36.     _delay_ms(5);
  37.     setPort(&PORTC, caracter);
  38.     _delay_ms(5);
  39.     setPort(&PORTB, 0x00);
  40.     _delay_ms(5);
  41. }
  42.  
  43. void PlaceCursor(uint8_t poz, uint8_t lin)
  44. {
  45.     uint8_t pozitie = 0x80;
  46.     pozitie |= poz;
  47.     pozitie |= (lin-1)<<6;
  48.     CommandLCD(pozitie);
  49. }
  50.  
  51. void ClearLCD()
  52. {
  53.     CommandLCD(0x01);
  54. }
  55.  
  56. void afisare_string(char sir[], uint8_t col, uint8_t lin)
  57. {
  58.     if(strlen(sir) + col > 15)
  59.         PlaceCursor(col-strlen(sir)+1, lin);
  60.     else
  61.         PlaceCursor(col, lin);
  62.     for(int i=0; sir[i] != '\0'; i++)
  63.         WriteLCD(sir[i]);
  64. }
  65.  
  66. void problema2()
  67. {
  68.     afisare_string("am",0,1);
  69.     afisare_string("afisat",15,1);
  70.     afisare_string("un",0,2);
  71.     afisare_string("text",15,2);
  72. }
  73.  
  74. void problema3()
  75. {
  76.     for(int i = 0; i<10;i++)
  77.     {
  78.         PlaceCursor(0,1);
  79.         WriteLCD(i+'0');
  80.         PlaceCursor(2,1);
  81.         WriteLCD(i+'0');
  82.         PlaceCursor(1,2);
  83.         WriteLCD(i+'0');
  84.         PlaceCursor(3,2);
  85.         WriteLCD(i+'0');
  86.         _delay_ms(1000);
  87.     }
  88. }
  89.  
  90. void problema4()
  91. {
  92.     uint8_t ora = 0;
  93.     uint8_t minut = 0;
  94. }
  95.  
  96. void scade_ora(uint8_t *ora)
  97. {
  98.     (*ora)--;
  99.     if(*ora<0)
  100.         *ora = 23;
  101. }
  102.  
  103. void creste_ora(uint8_t *ora)
  104. {
  105.     (*ora)++;
  106.     if(*ora>23)
  107.         *ora = 0;
  108. }
  109.  
  110. void scade_minut(uint8_t *ora, uint8_t *minut)
  111. {
  112.     (*minut)--;
  113.     if(*minut<0)
  114.     {
  115.         *minut = 59;
  116.         scade_ora(ora);
  117.     }
  118. }
  119.  
  120. void creste_minut(uint8_t *ora, uint8_t *minut)
  121. {
  122.     (*minut)++;
  123.     if(*minut>59)
  124.     {
  125.         *minut = 0;
  126.         creste_ora(ora);
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement