Advertisement
kajacx

MCU1

Nov 15th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.58 KB | None | 0 0
  1. /* Svoje jméno a příjmení a školu
  2.  * Trololo
  3.  * + dnešní datum
  4.  *
  5.  * knihovna funkcí pro práci s LCDhd44780 kompatibilní
  6.  *
  7.  * DB7:DB0 :: PORTD
  8.  * RS:: PORTE<0>
  9.  * RW:: PORTE<1>
  10.  * EN:: PORTE<2>
  11.  *
  12.  * PIC16F887A, fosc = 3.2768 MHz
  13.  */
  14.  
  15. #include "init.h"   // included by C-Wiz
  16. #include <htc.h>
  17.  
  18.  
  19. // definice řídících příkazů LCD
  20. #define LCD_CLEAR_DISPLAY   0b00000001
  21. #define LCD_RETURN_HOME     0b00000010
  22.  
  23. //left-to-right, dont shift
  24. #define LCD_MODE_SET        0b00000110
  25.  
  26. //display on, no cursor, no cursor blink
  27. #define LCD_DISPLAY_CONTROL 0b00001100
  28.  
  29. #define LCD_SHIFTS          0b00010000
  30.  
  31. //8-bit bus, 2-line display, small dots
  32. #define LCD_FUNCTION_SET    0b00111000
  33.  
  34. #define LCD_SET_CGRAM_ADDR  0b01000000
  35.  
  36. #define LCD_SET_DDRAM_ADDR  0b10000000
  37.  
  38. #define LCD_KOEF_W8         0.8
  39.  
  40.  
  41.  
  42. #define LCD_2ND_ROW 0x40
  43.  
  44. #define LCD_PORT PORTD
  45.  
  46. #define LCD_RS RE0
  47. #define LCD_RW RE1
  48. #define LCD_EN RE2
  49.  
  50. //podprogram pro cekani v us
  51. void lcd_wait_us(unsigned short int count) {
  52.     count = count >> 2;
  53.     do {
  54.         asm("nop");
  55.     } while(--count);
  56. }
  57.  
  58. //podprogram pro cekani v ms
  59. void lcd_wait_ms(unsigned char count) {
  60.     do {
  61.         lcd_wait_us(1000);
  62.     } while(--count);
  63. }
  64.  
  65. //inicializace displaye
  66. void lcd_init(void) {
  67.     //CLD_POWER = ON
  68.     lcd_wait_ms((unsigned char) (30 * LCD_KOEF_W8));
  69.     //lcd_cmd(CLD_FUNCTION_SET);
  70.     //lcd_cmd(CLD_DISPLAY_CONTROL);
  71.     //lcd_cmd(CLD_DISPLAY_CLEAR);
  72.     //lcd_cmd(CLD_ENTRY_MODE_SET);
  73. }
  74.  
  75. void main(void)
  76. {
  77.     init(); // Function call inserted by C-Wiz
  78.     while (1){
  79.         //TODO Auto-generated main function
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement