Lighting leds on matrix multimedia board

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:

Lighting leds on matrix multimedia board

Post by ukweb »

The following code does not work, it is supposed to be lighitng leds on porta, as the port b buttons are pressed.

Code: Select all

#include <system.h>

main()
{

while(1)
{
int count=0;
set_bit(STATUS, RP0); //SELECTS BANK 1
TRISA=0x00;  //MAKES PORTA outPUT
TRISB=0xff;  //MAKES PORTB inPUT
clear_bit(STATUS, RP0);  //SELECTS BANK 0
adcon1=0x07;
if(input_pin_port_b(7))
{
count=count+1;
}
else if(input_pin_port_b(6))
{
count=count-1;
}
if(count==1)
{
output_high_port_a(0);
}else
{
output_low_port_a(0);
}
if(count==2)
{
output_high_port_a(1);
}else
{
output_low_port_a(1);
}
if(count==3)
{
output_high_port_a(2);
}else
{
output_low_port_a(2);
}
}
}
Please check it and let me know. PIC 16f876 matrix multimedia version2 board. Is there any other way to make it work. thank you ukweb

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

Post by Ian »

Startup code needs to be in the startup not the main loop.
Also move the Anagloue>Digital IO to the start.

e.g. -
#include <system.h>

main()
{

adcon1=0x07; // Do Analogue port to digital IO first thing

set_bit(STATUS, RP0); //SELECTS BANK 1
TRISA=0x00; //MAKES PORTA outPUT
TRISB=0xff; //MAKES PORTB inPUT
clear_bit(STATUS, RP0); //SELECTS BANK 0

int count=0;

while(1)
{


if(input_pin_port_b(7))
{
count=count+1;
}
else if(input_pin_port_b(6))
{
count=count-1;
}

if(count==1)
{
output_high_port_a(0);
} else {
output_low_port_a(0);
}

if(count==2)
{
output_high_port_a(1);
} else {
output_low_port_a(1);
}

if(count==3)
{
output_high_port_a(2);
} else {
output_low_port_a(2);
}

// added a delay to see it working in XT
delay_s(1);

}
}


Also here is the corrected code for the other program you posted about.

#include <system.h>

main()
{
adcon1=0x07; // Do Analogue port to digital IO first thing

set_bit(STATUS, RP0); //SELECTS BANK 1
TRISB=0x00; //MAKES PORTB OUTPUT
TRISA=0xff; //MAKES PORTA INPUT
clear_bit(STATUS, RP0); //SELECTS BANK 0
if(input_pin_port_a(0))
{
PORTB=0xff;
} else {
PORTB=0x00;
}
}

Post Reply