Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help with bit pattern generation on pic16f877A ports!

Status
Not open for further replies.

fara793

Newbie level 4
Joined
Jan 25, 2010
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
jordan
Activity points
1,319
i need help

I am working on a project, but i dont know very much on mikrobasic, however, if someone can help me, i would be very grateful..

i am working on pic16f877A, and here is the program but its not working :( : can you please if out whats wrong?

Code:
PORTA=0
TRISA=0
PORTD=0
TRISD=0
PORTB=0
TRISB=255


main:

while true

    while  portB = 0

           portA =%00001100     
           portD =%00001001
           delay_ms (2000)
           portA =%00010010     
           portD =%00001001
           delay_ms (2000)
           portA =%00100001    
           portD =%00001001
           delay_ms (2000)
           portA =%00010001    
           portD =%00001010
           delay_ms (2000)
           portA =%00001001    
           portD =%00001100
           delay_ms (2000)
           portA =%00001001     
           portD =%00010010
           delay_ms (2000)
           portA =%00001001    
           portD =%00100001
           delay_ms (2000)
           portA =%00001010     
           portD =%00010001
           delay_ms (2000)

    wend

    if portB= %00000001 then
    
           portA =%00001100     
           portD =%00001001
           delay_ms (5000)

    end if


    if portB= %00000010 then
    
           portA =%00100001
           portD =%00001001
           delay_ms (5000)

    end if

    if portB= %00000100 then

           portA =%00001001
           portD =%00001100
           delay_ms (5000)
    end if

    if portB= %00001000 then
    
           portA =%00001001
           portD =%00100001
           delay_ms (2000)

    end if




wend

end.

THANK YOU!!
 

Re: i need help

Hi fara793,

Just tell us what output you are getting exactly. If you are trying to output some value on PORTA, then you need to configure it as digital I/O since it is initialised as analog input pin for ADC after reset. Put ADCON1=6 at the beginning. Also refer to the ADC section in the datasheet.
 

Re: i need help

my output is LED, but i dont think the problem is with them, what i think the problem is with PORTB as an input, i've never worked on input, so you told me that i have put ADCON1=6 at the beginning, but what is ADC for?
thank you for repling, i appreciate it :)
 

Re: i need help

Hi fara793,

ADC or Analog to Digital Converter is a peripheral device in PIC16F877. An ADC converts an analog input voltage to a digital value. So an ADC has input pins which can accept analog voltages. In PIC16F877, all pins in PORTA except RA4 is used as ADC input pins. When the device starts, these pins are configured as ADC inputs so normal digital input or output cannot be performed on these pins unless you modify the ADCON1 register contents. Setting ADCON=6 makes all the ADC input pins configured as analog inputs to becomes digital IOs. After this you can send values to PORTA to get a logic high or low.

I haven't worked with mikroBASIC. But I don't think there is anything wrong in using PORTB as inputs. Try not to float any input pins, either pull them high or low through a high value resistor(10K-47K).
 

Re: i need help

Insted of this portA =%00001001 try going for PORTA=0x09

Regards,
GAnesh
 

i need help

Hi,
Change your code to:
Code:
program something

main:
TRISA=0
PORTA=0
TRISD=0
PORTD=0
TRISB=255
ADCON1 = 6 'OR ADCON1 = 7, SAME THING
CMCON = 7

while true

    while  (portB = 0)

           portA =%00001100     
           portD =%00001001
           delay_ms (2000)
           portA =%00010010     
           portD =%00001001
           delay_ms (2000)
           portA =%00100001   
           portD =%00001001
           delay_ms (2000)
           portA =%00010001   
           portD =%00001010
           delay_ms (2000)
           portA =%00001001   
           portD =%00001100
           delay_ms (2000)
           portA =%00001001     
           portD =%00010010
           delay_ms (2000)
           portA =%00001001   
           portD =%00100001
           delay_ms (2000)
           portA =%00001010     
           portD =%00010001
           delay_ms (2000)

    wend

    if (portB= %00000001) then
   
           portA =%00001100     
           portD =%00001001
           delay_ms (5000)

    end if


    if (portB= %00000010) then
   
           portA =%00100001
           portD =%00001001
           delay_ms (5000)

    end if

    if (portB= %00000100) then

           portA =%00001001
           portD =%00001100
           delay_ms (5000)
    end if

    if (portB= %00001000) then
   
           portA =%00001001
           portD =%00100001
           delay_ms (2000)

    end if

wend
end.
The brackets for conditions aren't really necessary, I just use them for convenience of understanding.
Hope this helps.
Tahmid.
 

Re: i need help

I have tried in my mikro C compiler and your code works fine

Here you go:-

void main (void )
{
PORTA=0;
TRISA=0;
PORTD=0;
TRISD=0;
PORTB=0;
TRISB=255;

while(1)
{
while (PORTB = 0)
{
PORTA =0B00001100;
PORTD =0B00001001;
delay_ms (2000);
PORTA =0B00010010;
PORTD =0B00001001;
delay_ms (2000);
PORTA =0B00100001;
PORTD =0B00001001;
delay_ms (2000);
PORTA =0B00010001;
PORTD =0B00001010;
delay_ms (2000);
PORTA =0B00001001;
PORTD =0B00001100;
delay_ms (2000);
PORTA =0B00001001;
PORTD =0B00010010;
delay_ms (2000);
PORTA =0B00001001;
PORTD =0B00100001;
delay_ms (2000);
PORTA =0B00001010;
PORTD =0B00010001;
delay_ms (2000);

}

if (PORTB= 0B00000001)

PORTA =0B00001100;
PORTD =0B00001001;
delay_ms (5000);




if (PORTB= 0B00000010)

PORTA =0B00100001;
PORTD =0B00001001;
delay_ms (5000);



if (PORTB= 0B00000100)

PORTA =0B00001001;
PORTD =0B00001100;
delay_ms (5000);


if (PORTB= 0B00001000)

PORTA =0B00001001;
PORTD =0B00100001;
delay_ms (2000);



}


}


Enjoyyyyyyyyyy
 

i need help

Hi fara,
Your problem, I think, was that you set the PORTB, TRISB, etc bytes before the main program.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top