Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LCD module connections
- sbit LCD_RS at LATD2_bit;
- sbit LCD_EN at LATD3_bit;
- sbit LCD_D4 at LATD4_bit;
- sbit LCD_D5 at LATD5_bit;
- sbit LCD_D6 at LATD6_bit;
- sbit LCD_D7 at LATD7_bit;
- sbit LCD_RS_Direction at TRISD2_bit;
- sbit LCD_EN_Direction at TRISD3_bit;
- sbit LCD_D4_Direction at TRISD4_bit;
- sbit LCD_D5_Direction at TRISD5_bit;
- sbit LCD_D6_Direction at TRISD6_bit;
- sbit LCD_D7_Direction at TRISD7_bit;
- // End LCD module connections
- char txt1[] = "GreenDigit's";
- char txt2[] = "MultiMeter";
- char txt3[] = "Lcd4bit";
- char txt4[] = "example";
- //char i; // Loop variable
- sbit Switch at RB0_bit;
- char message1[] = "Capacitance";
- char message2[] = "Meter";
- unsigned int T_Value, Num;
- unsigned short i, j, TimerValue, OverRange = 0;
- char Capacitance[] = "00.000 uF";
- unsigned int Value = 0;
- void TimerInterrupt() iv IVT_ADDR_T2INTERRUPT ics ICS_AUTO
- {
- if(T2IF_bit == 1)
- {
- Value++;
- T2IF_bit = 0;
- }
- }
- void Display_Cap(unsigned int n){
- Capacitance[0] = n/10000 + 48;
- Capacitance[1] = (n/1000)%10 + 48;
- Capacitance[3] = (n/100)%10 + 48;
- Capacitance[4] = (n/10)%10 + 48;
- Capacitance[5] = (T_Value*10)/153 + 48;
- Lcd_Cmd(_Lcd_Clear);
- Lcd_Out(1, 1, "C = ");
- Lcd_Out(1, 5, Capacitance);
- }
- void Move_Delay() { // Function used for text moving
- Delay_ms(700); // You can change the moving speed here
- }
- void ComparorInterrupt() org 0x000038{
- /*if (IFS1BITS.CMIF == 1) // Check if INTF flag is set
- {*/
- IFS1BITS.CMIF = 0;
- Lcd_Out(2,5,"Yes Yes");
- //}
- }
- void Init()
- {
- TRISD = 0;
- PORTD = 0;
- TRISB = 0x18;
- //CM1CON = 0b10000000100000000;
- //CVRCON = 0x00;
- //IEC1 &= 2;
- // Comparator
- CM1CONBITS.CEN = 1;
- CM1CONBITS.COE = 0;
- CM1CONBITS.CPOL = 0;
- CM1CONBITS.CEVT = 0;
- CM1CONBITS.EVPOL = 0b10;
- CM1CONBITS.CREF = 0;
- CM1CONBITS.CCH = 0b00;
- CVRCONBITS.CVREN = 0;
- CVRCONBITS.CVROE = 0;
- IEC1BITS.CMIE = 1;
- // Timer controll
- T2CONBITS.T32 = 0;
- PR2 = 104;
- T2IE_bit = 1;
- NSTDIS_bit = 0;
- Lcd_Init();
- Lcd_Cmd(_Lcd_Clear);
- Lcd_Cmd(_LCD_CURSOR_OFF);
- Lcd_Out(1,3,txt1); // Write text in first row
- Lcd_Out(2,4,txt2); // Write text in second row
- }
- void main()
- {
- char cap_size;
- Init();
- Delay_ms(2000);
- Lcd_Cmd(_Lcd_Clear);
- Lcd_Out(1,3,message1);
- Delay_ms(2000);
- Lcd_Cmd(_Lcd_Clear);
- while(1)
- {
- /*if(C1OUT_bit == 1)
- {
- Lcd_Out(1,5,"High");
- }
- else
- {
- Lcd_Out(1,5,"Low ");
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement