// 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";
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 interrupt(void){
if (CMIF == 1) // Check if INTF flag is set
{
IFS1.CMIF_bit = 0;
Lcd_Out(1,5,"Yes Yes");
}
}
void Init()
{
TRISD = 0;
PORTD = 0;
TRISB = 0x18;
CM1CON = 0b10000000100000000;
CVRCON = 0x00;
IEC1 &= 2;
/*CM1CON.CEN = 1;
CM1CON.COE = 0;
CM1CON.CPOL = 0;
CM1CON.CEVT = 0;
CM1CON.EVPOL = 0b10;
CM1CON.CREF = 0;
CM1CON.CCH = 0b00;
CVRCON.CVREN = 0;
CVRCON.CVROE = 0;*/
IEC1.CMIE = 1;
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)
{
Lcd_Out(1,5,"High");
}
else
{
Lcd_Out(1,5,"Low ");
}
}
}