Simple output 2

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
ukweb
Posts: 16
Joined: Fri Jul 28, 2006 8:35 pm
Contact:

Simple output 2

Post 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.

Ian
Posts: 110
Joined: Thu Sep 29, 2005 10:53 am
Location: Matrix Multimedia
Been thanked: 1 time
Contact:

Post 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.

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post 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; 
    }
} 

Post Reply