Advertisement
GreenDigit

Untitled

Aug 25th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4. // LCD module connections
  5. sbit LCD_RS at LATD2_bit;
  6. sbit LCD_EN at LATD3_bit;
  7. sbit LCD_D4 at LATD4_bit;
  8. sbit LCD_D5 at LATD5_bit;
  9. sbit LCD_D6 at LATD6_bit;
  10. sbit LCD_D7 at LATD7_bit;
  11.  
  12. sbit LCD_RS_Direction at TRISD2_bit;
  13. sbit LCD_EN_Direction at TRISD3_bit;
  14. sbit LCD_D4_Direction at TRISD4_bit;
  15. sbit LCD_D5_Direction at TRISD5_bit;
  16. sbit LCD_D6_Direction at TRISD6_bit;
  17. sbit LCD_D7_Direction at TRISD7_bit;
  18. // End LCD module connections
  19.  
  20. char txt1[] = "GreenDigit's";
  21. char txt2[] = "MultiMeter";
  22. char txt3[] = "Lcd4bit";
  23. char txt4[] = "example";
  24.  
  25. //char i;                              // Loop variable
  26.  
  27. sbit Switch at RB0_bit;
  28. char message1[] = "Capacitance";
  29. char message2[] = "Meter";
  30. unsigned int T_Value, Num;
  31. unsigned short i, j, TimerValue, OverRange = 0;
  32. char Capacitance[] = "00.000 uF";
  33. unsigned int Value = 0;
  34.  
  35. void TimerInterrupt() iv IVT_ADDR_T2INTERRUPT ics ICS_AUTO
  36. {
  37.  if(T2IF_bit == 1)
  38.  {
  39.   Value++;
  40.   T2IF_bit = 0;
  41.  }
  42.  
  43. }
  44.  
  45. void Display_Cap(unsigned int n){
  46.   Capacitance[0] = n/10000 + 48;
  47.   Capacitance[1] = (n/1000)%10 + 48;
  48.   Capacitance[3] = (n/100)%10 + 48;
  49.   Capacitance[4] = (n/10)%10 + 48;
  50.   Capacitance[5] = (T_Value*10)/153 + 48;
  51.   Lcd_Cmd(_Lcd_Clear);
  52.   Lcd_Out(1, 1, "C = ");
  53.   Lcd_Out(1, 5, Capacitance);
  54. }
  55.  
  56.  
  57. void Move_Delay() {                  // Function used for text moving
  58.   Delay_ms(700);                     // You can change the moving speed here
  59. }
  60.  void ComparorInterrupt() org 0x000038{
  61.  
  62.   /*if (IFS1BITS.CMIF == 1)   // Check if INTF flag is set
  63.    {*/
  64.  
  65.     IFS1BITS.CMIF = 0;
  66.     Lcd_Out(2,5,"Yes Yes");
  67.    //}
  68.   }
  69. void Init()
  70. {
  71.   TRISD = 0;
  72.   PORTD = 0;
  73.   TRISB = 0x18;
  74.  
  75.   //CM1CON = 0b10000000100000000;
  76.   //CVRCON = 0x00;
  77.   //IEC1 &= 2;
  78.  
  79.   // Comparator
  80.   CM1CONBITS.CEN = 1;
  81.   CM1CONBITS.COE = 0;
  82.   CM1CONBITS.CPOL = 0;
  83.   CM1CONBITS.CEVT = 0;
  84.   CM1CONBITS.EVPOL = 0b10;
  85.   CM1CONBITS.CREF = 0;
  86.   CM1CONBITS.CCH = 0b00;
  87.   CVRCONBITS.CVREN = 0;
  88.   CVRCONBITS.CVROE = 0;
  89.   IEC1BITS.CMIE = 1;
  90.  
  91.   // Timer controll
  92.  
  93.   T2CONBITS.T32 = 0;
  94.   PR2 = 104;
  95.   T2IE_bit = 1;
  96.   NSTDIS_bit = 0;
  97.  
  98.  
  99.   Lcd_Init();
  100.   Lcd_Cmd(_Lcd_Clear);
  101.   Lcd_Cmd(_LCD_CURSOR_OFF);
  102.   Lcd_Out(1,3,txt1);                 // Write text in first row
  103.   Lcd_Out(2,4,txt2);                 // Write text in second row
  104. }
  105.  
  106. void main()
  107. {
  108.  
  109.   char cap_size;
  110.  
  111.   Init();
  112.   Delay_ms(2000);
  113.   Lcd_Cmd(_Lcd_Clear);
  114.   Lcd_Out(1,3,message1);
  115.   Delay_ms(2000);
  116.   Lcd_Cmd(_Lcd_Clear);
  117.  
  118.   while(1)
  119.   {
  120.    /*if(C1OUT_bit == 1)
  121.    {
  122.  
  123.     Lcd_Out(1,5,"High");
  124.    }
  125.    else
  126.    {
  127.     Lcd_Out(1,5,"Low ");
  128.    }*/
  129.   }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement