Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 13, 2024, 09:12:13 09:12


Login with username, password and session length


Pages: [1]
Print
Author Topic: Doing Parallel task with pic in basic  (Read 4070 times)
0 Members and 1 Guest are viewing this topic.
munaf
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 0
-Receive: 2


« on: October 24, 2007, 04:44:02 04:44 »

Dear Friends
I m a new in electronic.  I have no experience in programmining.  I want to learn it in basic.  I download many tutorials on PIC basic but nothing under stand. So I want to learn it from you all friends, I hope you shall be help me.
At first I write a basic program of LED blinking. It was done.
1.   Now I want to write a program “When the port A bit no.2 of 16F84A is “0” then LED on port B bit 0 is blinking permanent with the delay of 300 ms and other leds on port B on one by one with the delay of 500 ms. If bit no.2 is “1” then leds on bit no.0 and bit no.1 blinking permanent and other leds on port B are on off step by step.
It is only for learning purpose.
2.   Other question is that when I declare the port B as output to use command “OUTPUT PORTB” then some bits of portB like as RB4 0r RB7 is show high.  I use the Proteus 7.1 and Proton+ 2.1.3 for experiments. I also use the command TRISB = %0000000 but result is same.
here is the code I was written but not working
Device 16F84
    XTAL  = 4
   TRISA = %11111111
   TRISB = %00000000
   Symbol led = PortB.0
   Symbol led1 = PortB.1
   Symbol led2 = PortB.2
   Symbol led3 = PortB.3
   Symbol led4 = PortB.4
   Symbol led5 = PortB.5
   Symbol led6 = PortB.6
   Symbol led7 = PortB.7
   
   
    MAIN:
    IF PORTA.2 = 0 THEN
    GOTO BLINK
    ELSE
    GOTO BLINK1
        ENDIF
    GOTO MAIN
   
BLINK:
     HIGH LED
     DELAYMS 300      
     LOW LED
     DELAYMS 300   
     HIGH LED1
     DELAYMS 500      
     HIGH LED2
     DELAYMS 500      
     HIGH LED3
     DELAYMS 500   
     HIGH LED4
     DELAYMS 500      
     HIGH LED5
     DELAYMS 500      
     HIGH LED6
     DELAYMS 500   
     HIGH LED7
     DELAYMS 500   
     CLS
   GOTO BLINK
   
   BLINK1:
    HIGH LED
     DELAYMS 300      
     LOW LED
     DELAYMS 300   
     HIGH LED1
     DELAYMS 300      
     LOW LED1
     DELAYMS 300
     HIGH LED2
     DELAYMS 500      
     LOW LED2
     DELAYMS 500   
     HIGH LED3
     DELAYMS 500   
     LOW LED3
     DELAYMS 500   
      HIGH LED4
     DELAYMS 500      
     LOW LED4
     DELAYMS 500
     HIGH LED5
     DELAYMS 500      
     LOW LED5
     DELAYMS 500   
     HIGH LED6
     DELAYMS 500   
     LOW LED6
     DELAYMS 500   
     DELAYMS 500   
     HIGH LED7
     DELAYMS 500   
     LOW LED7
     DELAYMS 500
   GOTO BLINK1
   pleas tell me also how can we do some parallel task on pic as I say one or two leds blinking continually and other one by one.   
       
        I hope you will be help me
Sorry for poor English
[email protected]
Logged
tyildizak
Newbie
*
Offline Offline

Posts: 15

Thank You
-Given: 7
-Receive: 8


« Reply #1 on: October 24, 2007, 07:51:44 07:51 »

Try this code:
Code:
      Device 16F84
      XTAL  = 4
      TRISA = %11111111
      TRISB = 0
      PORTB = 0                  ;!!!
      Symbol led = PORTB.0
      Symbol led1 = PORTB.1
      Symbol led2 = PORTB.2
      Symbol led3 = PORTB.3
      Symbol led4 = PORTB.4
      Symbol led5 = PORTB.5
      Symbol led6 = PORTB.6
      Symbol led7 = PORTB.7
     
     
MAIN:
      If PORTA.2 = 0 Then
      GoTo BLINK
      Else
      GoTo BLINK1
      EndIf
     
      GOTO MAIN
     
BLINK:
      High led
      DelayMS 300     
      Low led
      DelayMS 300   
      High led1
      DelayMS 500     
      High led2
      DelayMS 500     
      High led3
      DelayMS 500   
      High led4
      DelayMS 500     
      High led5
      DelayMS 500     
      High led6
      DelayMS 500   
      High led7
      DelayMS 500   
      PORTB=0
      GoTo MAIN           ;!
     
BLINK1:
      High led
      DelayMS 300     
      Low led
      DelayMS 300   
      High led1
      DelayMS 300     
      Low led1
      DelayMS 300
      High led2
      DelayMS 500     
      Low led2
      DelayMS 500   
      High led3
      DelayMS 500   
      Low led3
      DelayMS 500   
      High led4
      DelayMS 500     
      Low led4
      DelayMS 500
      High led5
      DelayMS 500     
      Low led5
      DelayMS 500   
      High led6
      DelayMS 500   
      Low led6
      DelayMS 500   
      DelayMS 500   
      High led7
      DelayMS 500   
      Low led7
      GoTo MAIN
« Last Edit: October 24, 2007, 08:08:46 08:08 by tyildizak » Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 84


« Reply #2 on: October 24, 2007, 08:24:47 08:24 »

Hi munaf,
I do not have much time right now but I can give you some tips wich could help...

1.- There is no such thing as " paralell tasking " in a PIC . It is out of its cappabilities.
As you advance in your learning you will discover " interrupts " ( timer driven events ) wich could simulate parallel tasks . Have a deep look into the devices Data Sheet ( this last is mandatory : always do ).

2.- Your code is testing porta status only once !!! It will only derive to one of your routines ..... follow it logicaly with care. You will be looping inside  one of them.

3.- As for 2.- use command GOSUB - RETURN instead of GOTO. Study this commad in proton help you will easyly find out.

4.- For a tiny 16F84 you are wasting valuable space in defining to many variables , and long code ( space inside this chip is finite and scarse ... ) Imagine your output port PORTB as an 8 bit variable ( every bit is one of your leds ) . Thus , PORTB = 0 will put all bits ( leds ) to 0 ( off) ( PORTB = %00000000 ) . PORTB = 2 will light up led on bit 1 ( all others off ) and so on. (PORTB = %00000010 ) This way , you can acces any bit on PORTB directly. ( assigning numerical values to the port )

hope it will help and keep you up and going.

greetings
 
Logged
Ikaros
Junior Member
**
Offline Offline

Posts: 83

Thank You
-Given: 422
-Receive: 48


« Reply #3 on: October 24, 2007, 11:33:47 11:33 »

As I understand you case is something like multitasking. This matter is really deep, but you can simulate it by interrupts. Look at http://www.pbpgroup.com/modules/wfsection/article.php?articleid=19 where Darrel Taylor has published his simplified Interrupts in Basic with rapid response.

Start with the examples he gives and then try more complicated routines. I think is the way to go. Sorry that have no time to write code as example.

John
Logged
seinfield
Translator
Newbie
***
Offline Offline

Posts: 12

Thank You
-Given: 4
-Receive: 1


« Reply #4 on: October 25, 2007, 03:39:17 03:39 »

With or without interrupts it can be done.

I dont want to be rude, but it is just matter of imagination; and time to read the pic and compiler manual.

I wll try to give you an example, but i am still restoring my programming PC. As soon i finish it i will help you.

Wink
Logged
frasenci
Translator
Active Member
***
Offline Offline

Posts: 171

Thank You
-Given: 142
-Receive: 84


« Reply #5 on: October 26, 2007, 02:45:28 02:45 »

Very interesting seinfield .
No , you are not beeing rude , but your tip is not fair either,IMHO.

We should not tip a men given the task to empty his home bath tub full of water, to do it by using a tea spoon .
He can do that , yes he can. And he will probably suceed , some day , yes. ( ETA depends on tub and spoon size ). And the spooned water where to Huh
It is an imaginative solution , yes maybe it is imaginative and considered full off creativity.
But knowing that the tub has a plug at the bottom , with plumbing all the way down to the ocean ( or water treatment plant ) 
We can wait for nice examples , but should better use the plug. Simply because it is already there. And it works.
No need to reinvent the wheel.

I would say : let him discover the hidden power of timers and interrupts.
His leds will blink timely and as expected, sooner than thougt, leaving more time to code what "has to be coded ".

Greetings
Francisco
Logged
fernandodiaz
Junior Member
**
Offline Offline

Posts: 73

Thank You
-Given: 1
-Receive: 18


« Reply #6 on: October 26, 2007, 03:33:00 03:33 »

Test this sample


Device 16F84
    XTAL  = 4
   TRISA = %11111
   TRISB = %00000000
poke portb = 1
dim x as byte

x:
if porta.2=0 then
goto xx
else
goto xxx
endif



xx:
for x = 1 to 7
portb << 1  ' rotar 1 pos a izq
delayms 500
next x
goto x


xxx:
for x = 1 to 7
portb >> 1 ' rotar 1 pos a derecha
delayms 500
next x
goto x
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC