PIC16F877 volt&amp (adding switch for backlight of lcd)

Discussion on projects that are created by users and posted on mikroElektronika website.
Post Reply
Author
Message
Egor4eva
Posts: 12
Joined: 04 Sep 2016 05:14

PIC16F877 volt&amp (adding switch for backlight of lcd)

#1 Post by Egor4eva » 04 Sep 2016 06:31

Hi,

I'm new to pic microcontrollers, i have built a temp unit and goes fine......But

I Want to add a switch that will turn on/off the backlight of the lcd. and also add
a lm35 temp unit, that will maybe monitor the circuit's heat (and enable a fan as
needed)
And i'm not sure how to enable a pin or pins of a port as input or output?

Can someone help me please.

This is the program;
// LCD module connections
sbit LCD_RS at RB5_bit;
sbit LCD_EN at RB7_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;

sbit LCD_RS_Direction at TRISB5_bit;
sbit LCD_EN_Direction at TRISB7_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
// End LCD module connections

char look(int a)
{
switch(a)
{
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
case 4:
return '4';
case 5:
return '5';
case 6:
return '6';
case 7:
return '7';
case 8:
return '8';
case 9:
return '9';
default:
return '.';
}
}
void main()
{
unsigned int v,vp,ip,i;
char *volt = "00.0";
char *current = "0.00";
CMCON = 0x07;
TRISA = 0xFF;
ADCON1 = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

do
{
v = ADC_Read(2); // ADC value of channel 2 (voltage)
i = ADC_Read(3); // ADC value of channel 3 (current)
i = (i*4.89)/0.47; // Converting ADC value to mV
v = ((v*4.89)/20)*120; // Converting ADC value to mV
if(v!=vp || i!=ip )
Lcd_Cmd(_LCD_CLEAR);
vp = v;
ip = i;
volt[0] = look(v/10000);
volt[1] = look((v/1000)%10);
volt[3] = look((v/100)%10);
Lcd_Out(1,1,"Voltage = ");
Lcd_Out(1,11,volt);
Lcd_Out(1,16,"V");

current[0] = look(i/1000);
current[2] = look((i/100)%10);
current[3] = look((i/10)%10);
Lcd_Out(2,1,"Current = ");
Lcd_Out(2,11,current);
Lcd_Out(2,16,"A");
Delay_ms(250);
} while(1);
}


Regards Michael

Post Reply

Return to “User Projects”