AVR ISP adapter (avr109/910 compatible, using ATmega16)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
6.0KB

  1. /***************************************************************************
  2. * Copyright (C) 2006 - 2020 by Olaf Rempel *
  3. * razzor AT kopf MINUS tisch DOT de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; version 2 of the License, *
  8. * *
  9. * This program is distributed in the hope that it will be useful, *
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  12. * GNU General Public License for more details. *
  13. * *
  14. * You should have received a copy of the GNU General Public License *
  15. * along with this program; if not, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #include <avr/io.h>
  20. #include "display.h"
  21. #include "target.h"
  22. #if (USE_DISPLAY)
  23. static display_mode_t m_mode = DISPLAY_MODE_OFF;
  24. static char m_buffer[32];
  25. static uint8_t m_buffer_length = 0;
  26. static uint8_t m_buffer_pos = 0;
  27. /* ***********************************************************************
  28. * display_putc
  29. * *********************************************************************** */
  30. static void display_putc(uint8_t pos, char ch)
  31. {
  32. if (ch >= 'a' && ch <= 'z')
  33. {
  34. ch &= ~0x20;
  35. }
  36. PORTD = ((ch & 0x7E) << 1);
  37. PORTC = ((ch & 0x01) << 3) | (3 - (pos & 0x03));
  38. PORTC |= (1<<DISP_WR);
  39. } /* display_putc */
  40. /* ***********************************************************************
  41. * display_put4
  42. * *********************************************************************** */
  43. static void display_put4(const char * p_str)
  44. {
  45. display_putc(0, *p_str++);
  46. display_putc(1, *p_str++);
  47. display_putc(2, *p_str++);
  48. display_putc(3, *p_str++);
  49. } /* display_put4 */
  50. /* ***********************************************************************
  51. * _hexnibble
  52. * *********************************************************************** */
  53. static char _hexnibble(char value)
  54. {
  55. value &= 0x0F;
  56. return (value < 0x0A) ? ('0' + value)
  57. : ('A' + value - 0x0A);
  58. } /* _hexnibble */
  59. /* ***********************************************************************
  60. * display_show_string
  61. * *********************************************************************** */
  62. void display_show_string(const char * p_string, uint8_t append)
  63. {
  64. char * p_dst = m_buffer;
  65. uint8_t pos = 0;
  66. if (append)
  67. {
  68. p_dst += m_buffer_length;
  69. pos = m_buffer_length;
  70. }
  71. while ((pos < sizeof(m_buffer) -1) &&
  72. (*p_string != '\0'))
  73. {
  74. *p_dst++ = *p_string++;
  75. pos++;
  76. }
  77. *p_dst++ = ' ';
  78. m_buffer_length = pos;
  79. m_buffer_pos = 0;
  80. } /* display_show_string */
  81. /* ***********************************************************************
  82. * display_show_hex
  83. * *********************************************************************** */
  84. void display_show_hex(uint8_t value, uint8_t append)
  85. {
  86. char * p_dst = m_buffer;
  87. uint8_t pos = 0;
  88. if (append)
  89. {
  90. p_dst += m_buffer_length;
  91. pos = m_buffer_length;
  92. }
  93. if (pos < (sizeof(m_buffer) -3))
  94. {
  95. *p_dst++ = _hexnibble(value >> 4);
  96. *p_dst++ = _hexnibble(value);
  97. *p_dst++ = ' ';
  98. }
  99. m_buffer_length = pos +2;
  100. m_buffer_pos = 0;
  101. } /* display_show_hex */
  102. /* ***********************************************************************
  103. * display_set_mode
  104. * *********************************************************************** */
  105. void display_set_mode(display_mode_t mode)
  106. {
  107. m_mode = mode;
  108. } /* display_set_mode */
  109. /* ***********************************************************************
  110. * display_update
  111. * *********************************************************************** */
  112. void display_update(void)
  113. {
  114. static uint8_t update_timer;
  115. update_timer++;
  116. switch (m_mode)
  117. {
  118. default:
  119. case DISPLAY_MODE_OFF:
  120. display_put4(" ");
  121. break;
  122. case DISPLAY_MODE_RUN_ANIM:
  123. display_put4("RUN-");
  124. m_mode = DISPLAY_MODE_RUN_ANIM_LOOP;
  125. /* fallthrough */
  126. case DISPLAY_MODE_RUN_ANIM_LOOP:
  127. switch (update_timer & 0x18)
  128. {
  129. case 0x00:
  130. display_putc(3, '-');
  131. break;
  132. case 0x08:
  133. display_putc(3, '\\');
  134. break;
  135. case 0x10:
  136. display_putc(3, '1');
  137. break;
  138. case 0x18:
  139. display_putc(3, '/');
  140. break;
  141. default:
  142. break;
  143. }
  144. break;
  145. case DISPLAY_MODE_STATIC:
  146. display_put4(m_buffer);
  147. break;
  148. case DISPLAY_MODE_SCROLL:
  149. case DISPLAY_MODE_SCROLL_ONCE:
  150. if ((m_buffer_length != 0x00) &&
  151. (!(update_timer & 0x1F))
  152. )
  153. {
  154. display_put4(m_buffer + m_buffer_pos);
  155. if (m_buffer_pos <= (m_buffer_length -3))
  156. {
  157. m_buffer_pos++;
  158. }
  159. else
  160. {
  161. m_buffer_pos = 0x00;
  162. if (m_mode == DISPLAY_MODE_SCROLL_ONCE)
  163. {
  164. m_mode = DISPLAY_MODE_RUN_ANIM;
  165. }
  166. }
  167. }
  168. break;
  169. }
  170. } /* display_update */
  171. #endif /* (USE_DISPLAY) */