Thunderhorse312
Member level 1
Hi, i am having problems with the output pins of my PIC16F877A microcontroller because whenever i turn an output pin on there is less than 5 Volts found in that certain pin (i.e. RB0). I need the 5 volts to drive my relay also using a relay driver. I saw from my voltmeter that only 4 to 3 volts are outputted on the pins i turn on. How do i provide an output of 5V?
here's my code
In this code i am trying to open a pin from PORTB and PORTD so that i could drive relays. Thanks!
here's my code
Code:
#include <htc.h>
#include <pic16f877a.h>
#include "delay.c"
#define _XTAL_FREQ 20000000
__CONFIG(0x3FFE);
unsigned int ADCRead(unsigned char channel)
{
unsigned char l_byte, h_byte; //Variables in exchange for ADRESL and ADRESH
unsigned int ADR; //stores the Analog to Digital input value
ADCON0 = 0x81; //sets what channel to be used for analog input
DelayUs(50); //acquistion time delay
GO_DONE = 1; //start the A/D conversion
while(GO_DONE == 1); //wait for the bit to be cleared
l_byte = ADRESL; //set l_byte as ADRESL
h_byte = ADRESH; //set h_byte as ADRESH
ADR = (h_byte << 8)|l_byte; //shift ADRESH 8 places to the left and be ORed with ADRESL
return ADR;
}
void main(void)
{
#define Weight25 469
#define Weight30 474
#define Weight31 475
#define Weight35 479
#define Weight36 480
#define Weight40 484
#define Weight41 485
#define Weight46 490
#define Weight47 491
#define Weight52 496
#define Weight53 497
#define Weight58 502
#define Weight59 503
#define Weight64 508
#define Weight65 509
#define Weight70 514
#define Weight71 515
#define Weight76 520
#define Weight77 521
#define Weight82 526
#define Weight83 527
#define Weight88 532
#define Weight89 533
#define Weight94 538
// #define Weight95 539
// #define Weight100 544
unsigned int Ch0,i; //initialize variable for Analog input voltage
CMCON = 7; //disable comparator
PORTD = 0;
TRISD = 0;
PORTB = 0;
TRISB = 0;
ADCON0 = 0x81;
ADCON1 = 0xC0;
while (1)
{
Ch0 = ADCRead(0);
if (Ch0 >= Weight25)
{
if (Ch0 <= Weight30)
{
RB0 = 1;
}
else
{
RB0 = 0;
}
}
else
{
RB0 = 0;
}
if (Ch0 >= Weight31) //weight 31 - 35
{
if (Ch0 <= Weight35)
{
RB1 = 1;
}
else
{
RB1 = 0;
}
}
else
{
RB1 = 0;
}
if (Ch0 >= Weight36) //weight 36 - 40
{
if (Ch0 <= Weight40)
{
RB2 = 1;
}
else
{
RB2 = 0;
}
}
else
{
RB2 = 0;
}
if (Ch0 >= Weight41) //weight 41 - 46
{
if (Ch0 <= Weight46)
{
RB3 = 1;
}
else
{
RB3 = 0;
}
}
else
{
RB3 = 0;
}
if (Ch0 >= Weight47) //weight 47 - 52
{
if (Ch0 <= Weight52)
{
RB4 = 1;
}
else
{
RB4 = 0;
}
}
else
{
RB4 = 0;
}
if (Ch0 >= Weight53) //weight 53 - 58
{
if (Ch0 <= Weight58)
{
RB5 = 1;
}
else
{
RB5= 0;
}
}
else
{
RB5 = 0;
}
if (Ch0 >= Weight59) //weight 59 - 64
{
if (Ch0 <= Weight64)
{
RB6 = 1;
}
else
{
RB6 = 0;
}
}
else
{
RB6 = 0;
}
if (Ch0 >= Weight65) //weight 65 - 70
{
if (Ch0 <= Weight70)
{
RD0 = 1;
}
else
{
RD0 = 0;
}
}
else
{
RD0 = 0;
}
if (Ch0 >= Weight71) //weight 71 - 76
{
if (Ch0 <= Weight76)
{
RD1 = 1;
}
else
{
RD1 = 0;
}
}
else
{
RD1 = 0;
}
if (Ch0 >= Weight77) //weight 77 - 82
{
if (Ch0 <= Weight82)
{
RD2 = 1;
}
else
{
RD2 = 0;
}
}
else
{
RD2 = 0;
}
if (Ch0 >= Weight83) //weight 83 - 89
{
if (Ch0 <= Weight89)
{
RD3 = 1;
}
else
{
RD3 = 0;
}
}
else
{
RD3 = 0;
}
}
return;
}
In this code i am trying to open a pin from PORTB and PORTD so that i could drive relays. Thanks!