dpd201.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * dpd201.c
  3. *
  4. * Copyright 2023 dh33ex <dh33ex@riseup.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301, USA.
  20. *
  21. *
  22. */
  23. #ifndef __msp430_h_
  24. #include <msp430.h>
  25. #endif
  26. #include "dpd201.h"
  27. void VFD_init(void) {
  28. P1SEL = BIT2 ; /* P1.2 = TXD */
  29. P1SEL2 = BIT2;
  30. UCA0CTL1 |= UCSSEL_2; /* SMCLK */
  31. UCA0BR0 = 104; /* 1MHz 9600 */
  32. UCA0BR1 = 0; /* 1MHz 9600 */
  33. UCA0MCTL = UCBRS0; /* modulation UCBRSx = 1 */
  34. UCA0CTL1 &= ~UCSWRST; /* unhold reset */
  35. }
  36. void VFD_write(char *text) {
  37. unsigned short i = 0;
  38. do {
  39. while (!(IFG2 & UCA0TXIFG)); /* wait until UART is free */
  40. UCA0TXBUF = 255 - 2*text[i]; /* encode byte and send */
  41. } while (text[++i] != '\0'); /* do it until zero-symbol */
  42. }
  43. void VFD_clear(void) {
  44. char _clr[] = {0x0C, '\0'}; /* creat packet with CLR command */
  45. VFD_write(_clr); /* send this packet */
  46. }
  47. void VFD_brightness(unsigned char n) {
  48. char _data[] = {0x1F, 0x58, n, '\0'}; /* creat packet with brightness command */
  49. VFD_write(_data); /* send this packet */
  50. }
  51. void VFD_set_address(unsigned char x, unsigned char y) {
  52. char _data[] = {0x1B, 0x48, x + 20*y, '\0'}; /* creat packet with position command */
  53. VFD_write(_data); /* send this packet */
  54. }