Page 1 of 1

Simple output 2

Posted: Mon Aug 21, 2006 10:32 am
by ukweb
Hi
I have added the code adcon1=0x07 to it, but even then it doesn't work

Matrix Multimedia board PIC 16f876

Code: Select all

#include <system.h>

main()
{

set_bit(STATUS, RP0); //SELECTS BANK 1
TRISB=0x00;  //MAKES PORTB OUTPUT
TRISA=0xff;  //MAKES PORTA INPUT
clear_bit(STATUS, RP0);  //SELECTS BANK 0
adcon1=0x07;
if(input_pin_port_a(0))
{
PORTB=0xff;
}
else
PORTB=0x00;
}
The above code should be turning all leds connected to PORTB on when bit 0 of PORTA is set, otherwise turned off.

And also i have know what the oscillator setting should be for this. XT or RC or HS.

Posted: Tue Aug 22, 2006 4:28 pm
by Ian
Try with adcon1 the very first thing, before the TRISA stuff.

XT, HS (XT setting on board) and RC (RC setting on board) need to match in the config and the board clock switch, but should work in either. RC may be very slow for some stuff, but works well with basic tutorial type programs.

Check Watchdog is off as that can keep resetting programs.

Posted: Mon Aug 28, 2006 3:06 pm
by Steve
The adcon1 register is in bank 1, so you need to set its value when the RP0 bit of the status register is set, ie:

Code: Select all

#include <system.h> 

main() 
{ 
    set_bit(STATUS, RP0);    //SELECTS BANK 1 
    TRISB=0x00;              //MAKES PORTB OUTPUT 
    TRISA=0xff;              //MAKES PORTA INPUT 
    adcon1=0x07;             //Set all A/D i/o lines to digital
    clear_bit(STATUS, RP0);  //SELECTS BANK 0 
    if(input_pin_port_a(0)) 
    { 
        PORTB=0xff; 
    } else {
        PORTB=0x00; 
    }
}