VFD 1x16 ze sterownikiem PT6302LQ

Język C dla mikrokontrolerów ARM
ODPOWIEDZ
Awatar użytkownika
SunRiver
Użytkownik
Posty: 1488
Rejestracja: 08 paź 2017, 11:27
Lokalizacja: Festung Oppeln
Kontakt:

VFD 1x16 ze sterownikiem PT6302LQ

Post autor: SunRiver »

Od naszego czasem się pokazującego na forum kolegi Cybersoft , wpadły mi w ręce takie dosyć fajne panele
z Wyświetlaczami VFD 1x16 oraz klawiaturą, IR i kilkoma diodami.

Obrazek

Płytka ta posiada na pokładzie sterownik PT6302LQ-001 sterujący wyświetlaczem LCD oraz PT6958 czyli sterownik klawiatury i led

Obrazek

Na początek trzeba było rozwiązać zagadkę , który pin jest czym na złączu 10 pin , miernik w łapkę i szukamy
Złącze to tradycyjne 2x5IDC które musiałem wyciąć i tym sposobem została taśma 10 przewodowa, a jej połączenia są następujące:

(nie opisuję tak jak 2 IDC -- liczę od przewodu czerwonego)

1 -- IR DATA -- sygnał z odbiornika podczerwieni
2 -- GND
3 -- CLK (6302 i 6958)
4 -- DIN (6302 i 6958)
5 -- CS (6958)
6 -- nie znalazłem
7 -- CS (6302)
8 -- nie znalazłem
9 -- VCC 5V
10 -- RST (6302)

Obrazek

Do testów będzie użyta płytka STM32Butterfly2 z STM32F107VC
Tym sposobem powstała wstępna biblioteka obsługująca wyświetlacz z użyciem bibliotek HAL

-----> PT6302.h
  1.  
  2. #ifndef __PT6302_H
  3. #define __PT6302_H
  4.  
  5. #include "stm32f1xx_hal.h"
  6.  
  7. // Struktura kontekstu panelu VFD
  8. typedef struct {
  9.     SPI_HandleTypeDef *hspi;
  10.     GPIO_TypeDef *stb_port;
  11.     uint16_t stb_pin;
  12. } PT6302_HandleTypeDef;
  13.  
  14. // Prototypy funkcji
  15. void PT6302_Init(PT6302_HandleTypeDef *h);
  16. void PT6302_Clear(PT6302_HandleTypeDef *h);
  17. void PT6302_SetBrightness(PT6302_HandleTypeDef *h, uint8_t level);
  18. void PT6302_DisplayOn(PT6302_HandleTypeDef *h, uint8_t on);
  19. void PT6302_WriteData(PT6302_HandleTypeDef *h, uint8_t addr, const char *text);
  20. void PT6302_Print(PT6302_HandleTypeDef *h, const char *text);
  21.  
  22. #endif
  23.  
  24.  
--- PT6302.c
  1.  
  2. #include "pt6302.h"
  3. #include <string.h>
  4.  
  5. #define PT6302_CMD_DISPLAY_MODE   0x00
  6. #define PT6302_CMD_DATA_SET       0x40
  7. #define PT6302_CMD_ADDR_SET       0xC0
  8. #define PT6302_CMD_DISPLAY_CTRL   0x80
  9.  
  10. // --- Wewnętrzna funkcja przesyłania bajtu przez SPI ---
  11. static void PT6302_Send(PT6302_HandleTypeDef *h, uint8_t data)
  12. {
  13.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
  14.     HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
  15.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
  16. }
  17.  
  18. // --- Inicjalizacja wyświetlacza ---
  19. void PT6302_Init(PT6302_HandleTypeDef *h)
  20. {
  21.     HAL_Delay(50);
  22.     PT6302_Send(h, PT6302_CMD_DISPLAY_MODE | 0x03); // tryb 16 znaków, 1 linia
  23.     PT6302_SetBrightness(h, 7);
  24.     PT6302_DisplayOn(h, 1);
  25.     PT6302_Clear(h);
  26. }
  27.  
  28. // --- Włączenie/wyłączenie wyświetlacza ---
  29. void PT6302_DisplayOn(PT6302_HandleTypeDef *h, uint8_t on)
  30. {
  31.     PT6302_Send(h, PT6302_CMD_DISPLAY_CTRL | (on ? 0x08 : 0x00) | 0x07);
  32. }
  33.  
  34. // --- Jasność (0–7) ---
  35. void PT6302_SetBrightness(PT6302_HandleTypeDef *h, uint8_t level)
  36. {
  37.     if (level > 7) level = 7;
  38.     PT6302_Send(h, PT6302_CMD_DISPLAY_CTRL | 0x08 | level);
  39. }
  40.  
  41. // --- Wyczyść wyświetlacz ---
  42. void PT6302_Clear(PT6302_HandleTypeDef *h)
  43. {
  44.     char buf[16];
  45.     memset(buf, ' ', sizeof(buf));
  46.     PT6302_WriteData(h, 0x00, buf);
  47. }
  48.  
  49. // --- Zapis tekstu od danej pozycji ---
  50. void PT6302_WriteData(PT6302_HandleTypeDef *h, uint8_t addr, const char *text)
  51. {
  52.     uint8_t len = strlen(text);
  53.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
  54.     uint8_t cmd = PT6302_CMD_ADDR_SET | addr;
  55.     HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
  56.     HAL_SPI_Transmit(h->hspi, (uint8_t*)text, len, HAL_MAX_DELAY);
  57.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
  58. }
  59.  
  60. // --- Skrót: wydrukuj od początku ---
  61. void PT6302_Print(PT6302_HandleTypeDef *h, const char *text)
  62. {
  63.     PT6302_WriteData(h, 0x00, text);
  64. }
  65.  
--- PT6958.h
  1.  
  2. #ifndef __PT6958_H
  3. #define __PT6958_H
  4.  
  5. #include "stm32f1xx_hal.h"
  6.  
  7. typedef struct {
  8.     SPI_HandleTypeDef *hspi;
  9.     GPIO_TypeDef *stb_port;
  10.     uint16_t stb_pin;
  11. } PT6958_HandleTypeDef;
  12.  
  13. void PT6958_Init(PT6958_HandleTypeDef *h);
  14. void PT6958_SetLED(PT6958_HandleTypeDef *h, uint8_t led_index, uint8_t state);
  15. uint16_t PT6958_ReadKeys(PT6958_HandleTypeDef *h);
  16.  
  17. #endif
  18.  
  19.  

--- PT6958.c
  1.  
  2. #include "pt6958.h"
  3.  
  4. #define PT6958_CMD_WRITE_DISPLAY  0x40
  5. #define PT6958_CMD_ADDR_SET       0xC0
  6. #define PT6958_CMD_DISPLAY_CTRL   0x80
  7.  
  8. static void PT6958_Send(PT6958_HandleTypeDef *h, uint8_t data)
  9. {
  10.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
  11.     HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
  12.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
  13. }
  14.  
  15. void PT6958_Init(PT6958_HandleTypeDef *h)
  16. {
  17.     PT6958_Send(h, PT6958_CMD_WRITE_DISPLAY);
  18.     PT6958_Send(h, PT6958_CMD_DISPLAY_CTRL | 0x0F); // Display ON, brightness max
  19. }
  20.  
  21. void PT6958_SetLED(PT6958_HandleTypeDef *h, uint8_t led_index, uint8_t state)
  22. {
  23.     uint8_t addr = 0x00 + led_index;
  24.     uint8_t data = state ? 0xFF : 0x00;
  25.  
  26.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
  27.     uint8_t cmd = PT6958_CMD_ADDR_SET | addr;
  28.     HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
  29.     HAL_SPI_Transmit(h->hspi, &data, 1, HAL_MAX_DELAY);
  30.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
  31. }
  32.  
  33. uint16_t PT6958_ReadKeys(PT6958_HandleTypeDef *h)
  34. {
  35.     uint8_t cmd = 0x42;
  36.     uint8_t buf[2] = {0};
  37.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_RESET);
  38.     HAL_SPI_Transmit(h->hspi, &cmd, 1, HAL_MAX_DELAY);
  39.     HAL_SPI_Receive(h->hspi, buf, 2, HAL_MAX_DELAY);
  40.     HAL_GPIO_WritePin(h->stb_port, h->stb_pin, GPIO_PIN_SET);
  41.  
  42.     return (buf[1] << 8) | buf[0];
  43. }
  44.  
To na razie tylko szkielet jeszcze nie testowałem bo wyświetlacze zostały w pracy...
Nie mniej powinno zadziałać. W załączniku noty obu układów:
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
Awatar użytkownika
gufim
Użytkownik
Posty: 170
Rejestracja: 16 paź 2017, 16:58

Re: VFD 1x16 ze sterownikiem PT6302LQ

Post autor: gufim »

No pięknie my tu gadu gadu a Sun sie zbroi w wyświetlacze :)
ODPOWIEDZ

Wróć do „C dla ARM”