Advertisement
Guest User

potenio display

a guest
Nov 21st, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. /* TFT module connections */
  2. char TFT_DataPort at LATE;
  3. sbit TFT_RST at LATD7_bit;
  4. sbit TFT_BLED at LATD2_bit;
  5. sbit TFT_RS at LATD9_bit;
  6. sbit TFT_CS at LATD10_bit;
  7. sbit TFT_RD at LATD5_bit;
  8. sbit TFT_WR at LATD4_bit;
  9. char TFT_DataPort_Direction at TRISE;
  10. sbit TFT_RST_Direction at TRISD7_bit;
  11. sbit TFT_BLED_Direction at TRISD2_bit;
  12. sbit TFT_RS_Direction at TRISD9_bit;
  13. sbit TFT_CS_Direction at TRISD10_bit;
  14. sbit TFT_RD_Direction at TRISD5_bit;
  15. sbit TFT_WR_Direction at TRISD4_bit;
  16. /* End TFT module connections */
  17.  
  18. int i, j;
  19. int cnt, speed = 0;
  20. unsigned int tempAdcValue;
  21. void main() {
  22. /* Setting output frequency to 140MHz */
  23. PLLFBD = 70; // PLL multiplier M=70
  24. CLKDIV = 0x0000;
  25. // PLL prescaler N1=2, PLL postscaler N2=2
  26.  
  27. ANSELA = 0x0000;
  28. TRISA = 0x00F0;
  29. LATA = 0x0000;
  30.  
  31. ANSELB = 0x0001; /* Conf. RB0 as analog - DSPIC specific. */
  32. TRISB0_bit = 1; /* Set PORTB.B0 as input (AN0) */
  33. ADC1_Init(); /* Default config of ADC module */
  34.  
  35. /* Init TFT */
  36. TFT_Set_Default_Mode();
  37. TFT_Init_ILI9341_8bit_Custom(320, 240);
  38. Delay_10ms();
  39.  
  40. /* Fill TFT screen with a color */
  41. TFT_Fill_Screen(CL_White);
  42. TFT_Set_Pen(CL_BLACK,5);
  43.  
  44. /*TFT_V_Line(100, 150, 10);
  45. TFT_V_Line(100, 150, 50);
  46. TFT_H_Line(10+cnt,50,150);
  47. TFT_H_Line(10+cnt,50,100);*/
  48. while(1)
  49. {
  50. tempAdcValue = ADC1_Get_Sample(0);
  51.  
  52. if ( (tempAdcValue > 0) && (tempAdcValue <= 255))
  53. {
  54. speed = 1;
  55. }
  56. if ( (tempAdcValue > 255) && (tempAdcValue <= 512))
  57. {
  58. speed = 5;
  59. }
  60.  
  61. if ( tempAdcValue > 512)
  62. {
  63. speed = 10;
  64. }
  65.  
  66.  
  67. // Vdelay_ms(tempAdcValue);
  68.  
  69. if((PORTA & 0x0020) == 0){
  70. cnt+=speed;
  71. TFT_Fill_Screen(CL_White);
  72. TFT_V_Line(100, 150, 10+cnt);
  73. /*TFT_V_Line(100, 150, 50+cnt);
  74. TFT_H_Line(10+cnt,50+cnt,150);
  75. TFT_H_Line(10+cnt,50+cnt,100);*/
  76. Delay_100ms();
  77. }
  78.  
  79. if((PORTA & 0x0010) == 0){
  80. cnt-=speed;
  81. TFT_Fill_Screen(CL_White);
  82. TFT_V_Line(100, 150, 10+cnt);
  83. /* TFT_V_Line(100, 150, 50+cnt);
  84. TFT_H_Line(10+cnt,50+cnt,150);
  85. TFT_H_Line(10+cnt,50+cnt,100);*/
  86. Delay_100ms();
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement