Skip to content
Snippets Groups Projects
Select Git revision
  • 34c153edde856407e559d9e0168df6770e9ad7b6
  • main default protected
  • khj-main-patch-93822
3 results

lcdController.c

Blame
  • lcdController.c 8.58 KiB
    #include <arpa/inet.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/socket.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <pthread.h>
    #include <wiringPi.h>
    #include <wiringPiI2C.h>
    #include <wiringPi.h>
    #include <stdbool.h>
    
    #define I2C_ADDR   0x27 // LCD 주소
    
    #define LCD_CHR  1 // Mode - Sending data
    #define LCD_CMD  0 // Mode - Sending command
    
    #define LINE1  0x80 // 첫번째 줄
    #define LINE2  0xC0 // 두번째 줄
    
    #define LCD_BACKLIGHT   0x08  // On
    // LCD_BACKLIGHT = 0x00  # Off
    
    #define ENABLE  0b00000100 // Enable bit
    
    
    #define MSG_SIZE 1024
    
    #define IN 0
    #define OUT 1
    #define PWM 0
    
    #define LOW 0
    #define HIGH 1
    #define VALUE_MAX 256
    #define DIRECTION_MAX 256
    
    
    
    void lcd_init(void);
    void lcd_byte(int bits, int mode);
    void lcd_toggle_enable(int bits);
    void lcdLoc(int line); //move cursor
    void ClrLcd(void); // clr LCD return home
    void typeln(const char *s);
    int fd;  // seen by all subroutines
    
    char msg[MSG_SIZE] = {0};
    char tempMsg[MSG_SIZE] = {0};
    static int PWMExport(int pwmnum) {
    #define BUFFER_MAX 3
      char buffer[BUFFER_MAX];
      int fd, byte;
    
      fd = open("/sys/class/pwm/pwmchip0/export", O_WRONLY);
      if (-1 == fd) {
        fprintf(stderr, "Failed to open export for export!\n");
        return (-1);
      }
    
      byte = snprintf(buffer, BUFFER_MAX, "%d", pwmnum);
      write(fd, buffer, byte);
      close(fd);
    
      sleep(1);
    
      return (0);
    }