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.

a beginner needs help with programming !!

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
a beginner needs help!!

i am working in project, and i dont how to complete, so please help me, its urgent!!

i need this code to be in a loop:

Code:
           portA =%00001100     '(1)
           portD =%00001001
           delay_ms (2000)
           portA =%00010010     ' 1-2
           portD =%00001001
           delay_ms (2000)
           portA =%00100001     '(2)
           portD =%00001001
           delay_ms (2000)
           portA =%00010001     ' 2-3
           portD =%00001010
           delay_ms (2000)
           portA =%00001001     ' 3-4
           portD =%00010010
           delay_ms (2000)
           portA =%00001001     '(4)
           portD =%00100001
           delay_ms (2000)
           portA =%00001010     ' 4-1
           portD =%00010001
           delay_ms (2000)

but if portB=%00000001, i need it to stop the loop and do this:

Code:
           portA =%00001100
           portD =%00001001
           delay_ms (5000)
and then get back to the beginning of the loop,

and the same thing when portB= %00000010

Code:
           portA =%00100001
           portD =%00001001
           delay_ms (5000)

and the same here when portB= %00000100

Code:
           portA =%00001001
           portD =%00001100
           delay_ms (5000)

and the same here too when portB= %00001000

Code:
           portA =%00001001
           portD =%00100001
           delay_ms (2000)


THANK YOU!!! :) :)
 

Re: a beginner needs help!!

In C it's a piece of cake!


Code:
void main() 
  {
  while(true)
    {
    portA = %00001100;
    portD = %00001001; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      }
 
    portA = %00010010;      
    portD = %00001001; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      }
 
    portA = %00100001;      
    portD = %00001001; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      }
 
    portA = %00010001;      
    portD = %00001010; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      } 

    portA = %00001001;    
    portD = %00010010; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      }
 
    portA = %00001001;     
    portD = %00100001; 
    delay_ms(2000);

    if(check_port_B){
      continue;
      }
 
    portA = %00001010;     
    portD = %00010001; 
    delay_ms(2000);
    } 
  }

/*--- Check Port B ---*/

Bool check_port_B(void)
  {
  Bool result;
  unsigned char port_value;

  port_value = portB;
  
  switch(port_value)
    {
    case %00000001: portA = %00001100; 
                    portD = %00001001; 
                    delay_ms(5000);
                    result = true;
                    break;

    case %00000010: portA = %00100001; 
                    portD = %00001001; 
                    delay_ms(5000);
                    result = true;
                    break;

    case %00000100: portA = %00001001; 
                    portD = %00001100; 
                    delay_ms(5000);
                    result = true;
                    break;

    case %00001000: portA = %00001001; 
                    portD = %00100001; 
                    delay_ms(2000);
                    result = true;
                    break;

    default:  result = false;
              break;

    }

  return result;
  }
 

a beginner needs help!!

btbass, your code will do nicely unless port B changes in less than ~10000 ms, but you risk to lose a lot of transitions on port B while you execute
delay_ms(2000);
or
delay_ms(5000); in main()!
BTW, there is no need to post the same problem twice - even when urgent!
 

a beginner needs help!!

Hi,
I guess this should do the trick:
Make sure you pull-up PORTA4 with a resistor.
The code could have been even smaller, but I tried to make it simple.
Code:
program leddance

const PORTAVal as byte[11] = (%00001100, %00010010, %00100001, %00010001, %00001001, %00001001, %00001010, %00001100, %00100001, %00001001, %00001001)
const PORTDVal as byte[11] = (%00001001, %00001001, %00001001, %00001010, %00010010, %00100001, %00010001, %00001001, %00001001, %00001100, %00100001)

dim count, count2, count3 as byte

main:
     TRISB = 255
     TRISA = 0
     TRISD = 0
     PORTA = 0
     PORTD = 0
     ADCON1 = 7
     CMCON = 7
     while true
           while (PORTB = 0)
                 PORTA = PORTAVal[count]
                 PORTD = PORTDVal[count]
                 for count2 = 1 to 200
                     if (PORTB = 0) then
                        delay_ms(10)
                     end if
                 next count2
                 Inc(count)
                 if (count > 6) then
                    count = 0
                 end if
           wend
           count = 0
           if (PORTB = %00000001) then
              delay_ms(30)
              PORTA = PORTAVal[7]
              PORTD = PORTDVal[7]
              for count3 = 1 to 200
                  if (PORTB = 0) or (PORTB = 1) then
                     delay_ms(25)
                  end if
              next count3
           end if
           if (PORTB = %00000010) then
              delay_ms(30)
              PORTA = PORTAVal[8]
              PORTD = PORTDVal[8]
              for count3 = 1 to 200
                  if (PORTB = 0) or (PORTB = 2) then
                     delay_ms(25)
                  end if
              next count3
           end if
           if (PORTB = %00000100) then
              delay_ms(30)
              PORTA = PORTAVal[9]
              PORTD = PORTDVal[9]
              for count3 = 1 to 200
                  if (PORTB = 0) or (PORTB = 4) then
                     delay_ms(25)
                  end if
              next count3
           end if
           if (PORTB = %00001000) then
              delay_ms(30)
              PORTA = PORTAVal[10]
              PORTD = PORTDVal[10]
              for count3 = 1 to 200
                  if (PORTB = 0) or (PORTB = 8) then
                     delay_ms(25)
                  end if
              next count3
           end if
     wend
end.
Tahmid.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top