oTaRu
Junior Member level 2
Hi, I having this problem with PIC16F877. Whenever I place a 5v to the input port (PORT A) of PIC16F877, the output ports (PORT B & PORT D) do not have the same 5v as input port... The result is either 1.3mv or 0.6mv when I uses multimeter to measure...
Below is the code:
#ifndef __CPU_16F877__
#error "This program is tailored for PIC16F877 controller"
#endif
#include "io16f877.h" //the hardware register definition file.
int timer_value=0xEA60; //decimal 60000.
void DelayUs(int count)
{
int i;
int j;
for(i=0;i<count;i++)
{
for(j=0;j<5000;j++);
//This for loop has 5 NOPs & wastes 1 uS for our PIC clock frequency of 20MHz.
}
}
void initialize_IO_ports(void)
{
//set the digital IO ports as per requirement.
TRISA = 0xFF ; //portA as input.
TRISB = 0x00 ; //portB as output.
TRISD = 0x00;
//clear the output ports at the beginning.
PORTA = 0x00 ; //clear portD.
PORTB = 0x00;
PORTD = 0x00;
}
void initialize_timer1(void)
{
TMR1CS=0;
// set prescalar value of 1:8 i.e. timer1 count=8x200ns=1600nS.
T1CKPS1=1;
T1CKPS0=1;
//Refer to the datasheet for the organization of interrupts.
GIE=1; //global interrupt enabled.
PEIE=1; //peripheral interrupt enabled.
TMR1IE=1; //enable timer1 interrupt.
}
// This function loads timer_value in timer1, & enables it.
void load_timer1(int timer_value)
{
TMR1ON=0; //disable timer1 before loading the values.
TMR1IF=0; //timer1 flag cleared.
TMR1H=(0xFFFF-timer_value)>>8; //load timer1 high register.
TMR1L=0xFFFF-timer_value; //load timer1 low register.
TMR1ON=1; //enable timer1.
}
int main()
{
initialize_IO_ports();
initialize_timer1();
load_timer1(timer_value);
while (1)
{
if (RA0==1)
{
RB0=1;
RB1=1;
RB2=1;
RD0=1;
RD1=1;
RD2=1;
}
else
{
RB0=0;
RB1=0;
RB2=0;
RD0=0;
RD1=0;
RD2=0;
}
}
}
/*end of program*/
Thanks!!
Below is the code:
#ifndef __CPU_16F877__
#error "This program is tailored for PIC16F877 controller"
#endif
#include "io16f877.h" //the hardware register definition file.
int timer_value=0xEA60; //decimal 60000.
void DelayUs(int count)
{
int i;
int j;
for(i=0;i<count;i++)
{
for(j=0;j<5000;j++);
//This for loop has 5 NOPs & wastes 1 uS for our PIC clock frequency of 20MHz.
}
}
void initialize_IO_ports(void)
{
//set the digital IO ports as per requirement.
TRISA = 0xFF ; //portA as input.
TRISB = 0x00 ; //portB as output.
TRISD = 0x00;
//clear the output ports at the beginning.
PORTA = 0x00 ; //clear portD.
PORTB = 0x00;
PORTD = 0x00;
}
void initialize_timer1(void)
{
TMR1CS=0;
// set prescalar value of 1:8 i.e. timer1 count=8x200ns=1600nS.
T1CKPS1=1;
T1CKPS0=1;
//Refer to the datasheet for the organization of interrupts.
GIE=1; //global interrupt enabled.
PEIE=1; //peripheral interrupt enabled.
TMR1IE=1; //enable timer1 interrupt.
}
// This function loads timer_value in timer1, & enables it.
void load_timer1(int timer_value)
{
TMR1ON=0; //disable timer1 before loading the values.
TMR1IF=0; //timer1 flag cleared.
TMR1H=(0xFFFF-timer_value)>>8; //load timer1 high register.
TMR1L=0xFFFF-timer_value; //load timer1 low register.
TMR1ON=1; //enable timer1.
}
int main()
{
initialize_IO_ports();
initialize_timer1();
load_timer1(timer_value);
while (1)
{
if (RA0==1)
{
RB0=1;
RB1=1;
RB2=1;
RD0=1;
RD1=1;
RD2=1;
}
else
{
RB0=0;
RB1=0;
RB2=0;
RD0=0;
RD1=0;
RD2=0;
}
}
}
/*end of program*/
Thanks!!