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


Login with username, password and session length


Pages: [1]
Print
Author Topic: SOS pic basic  (Read 7757 times)
0 Members and 1 Guest are viewing this topic.
kctan
Guest
« on: December 01, 2005, 11:57:57 11:57 »

anyone can help me write a simple program by using the microcode studio plus ?
i need a simple program to refer like:
- When the sensor on then it will count as one and display at LCD (anyword)
- after it count until 5 the LCD will display (anyword) and when another input has on then it will return back initial program
i need to refer because i hang at the PIC input command so confuse
i using 5 v direct go in but not have output i try many port already but still no work
i try the output command and that is work
 
thanks 1st for anyone helping
thanks you
Logged
seinfield
Translator
Newbie
***
Offline Offline

Posts: 12

Thank You
-Given: 4
-Receive: 1


« Reply #1 on: December 03, 2005, 02:14:59 02:14 »

input command??

the input comand is to define a pin as an input.

The output is to define a pin as an output.

For example:

input portb.0               ' Trisb.0=1
output portb.1=0        ' Trisb.1= 0

If portb.0=1 then high portb.1     ' If at portb.0 there is 5volts it will put the portb.1 pin = 5v
else
low portb.1                                   'if not portb.1 = 0 volts
endif

now:
high portb.1 is the same as portb.1= 1
low portb.1 is the same as portb.1= 0

easy!!!
Logged
kctan
Guest
« Reply #2 on: December 04, 2005, 10:27:59 10:27 »

if using high command is that no have any error?
i saw someone using portb.0 = 1 or = 0
or using poke and peek but i dunno how to use that command
can u teach me? poke and peek command:D
Logged
seinfield
Translator
Newbie
***
Offline Offline

Posts: 12

Thank You
-Given: 4
-Receive: 1


« Reply #3 on: December 14, 2005, 04:24:31 04:24 »

Dont use peek and poke command, there is high and low command.
If you want to set all the pin's of the portb to 1's, just: portb = 255
or portb = %11111111 (from bit 7 to bit 0)
or portb = $FF
if you want to set a single pint to high (1's): portb.0 = 1
to 0´s : portb.0= 0

easy.
i use pbp.
Logged
kctan
Guest
« Reply #4 on: December 14, 2005, 09:18:51 09:18 »

at proton if i want using for loop command to counter how should i do?
if i want do count until 5 and i declare x as byte after it count until 5 it high portb.1, and portb.0 as the signal input for counter.
how x know the portb.0 is the counter when the portb.0 got signal.
if i declare x = portb.0, when at for loop like
for x = 0 to 5, what will happend to portb.0?
Logged
Rautrin
Guest
« Reply #5 on: January 02, 2006, 07:29:01 19:29 »

hola, soy de España, busco en la web,el compilador pic basic pro compiler gratis(free)
me podrias decir donde(WHERE?)
Logged
tasosstr
Junior Member
**
Offline Offline

Posts: 75

Thank You
-Given: 95
-Receive: 14


« Reply #6 on: January 02, 2006, 08:18:10 20:18 »

Hello,

You Say:

if i declare x = portb.0, when at for loop like  "Then the X has value 0 or 1"

for x = 0 to 5, what will happend to portb.0?

Next X
Here you have an empty code so does nothing ....

Clear to us what exacly you want so make us more eayse to help you.

Best Regards,
Tasos
Logged
metal
Global Moderator
Hero Member
*****
Offline Offline

Posts: 2420

Thank You
-Given: 862
-Receive: 678


Top Topic Starter


« Reply #7 on: January 02, 2006, 10:31:41 22:31 »

Hey

Peek and Poke commands seem to be obsolute....

If you configure a pin in a port to an input/output from within your code, then you can use Port.Pin = 0/1.

If you want to make that pin an output directly with one command, you can use High/Low commands. Although Melabs recomend that:


Code:
[SIZE=2][B]TrisX.Pin[/B] = [COLOR=Red]0[/COLOR]/[COLOR=Red]1 [/COLOR]  [COLOR=Green]     ' Make a Pin an Output/Input respectively[/COLOR]
[B]PortX.Pin[/B] = [COLOR=Red]0[/COLOR]/[COLOR=Red]1[/COLOR]        [COLOR=Green]' Make the pin High/Low respectively[/COLOR][/SIZE]


be used Instead of using High/Low commands.

Regarding Input command, this one makes a PortX.Pin an input, It doesn't change the pin state. Also you better use TrisX.Pin to make a Pin as an Input.

MetaL
[/FONT]
Logged
kctan
Guest
« Reply #8 on: January 03, 2006, 07:30:07 07:30 »

thanks you all for help. but i get the problem and solve already. this is because my stupid connection about the circuit is wrong cause the problem occur. anywhere i am just a beginner . but very thanks u all because i get more reply and guide.
Logged
munaf
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 0
-Receive: 2


« Reply #9 on: May 03, 2006, 03:52:50 15:52 »

dear friends
i want to make a timer with pic 16f84a in Proton+.
please help me
i want:
1. when i on the suplly it delay 5 munite and then high port b Pin No. XXX.
2. if i press button on port a  then high the port b Pin No. xxx for 1 houre then low it for 15 munite and after it high it again for one houre. repeat it for ever.
 
please write the code for this in basic
 
sory for poor english.
thanks
Logged
Wizpic
Global Moderator
Hero Member
*****
Offline Offline

Posts: 1200

Thank You
-Given: 546
-Receive: 408



« Reply #10 on: May 03, 2006, 07:35:38 19:35 »

Munaf
If you want us to help you, you need to help yourself first,
You will mot find anybody that will write the code for you that's to easy
 
what you need to do is write some code and try to get it working if not them upload your code that you have wrote then we may be able to help you becuase what you want to do is asking a lot sorry to say
 
There is also quite a few ways you can do it using interuptts or then simple way here is some code to get you going
 
Code:
 [size=2]
[b]Device [/size][size=2][color=#000080]16F877

[/b][/color][/size][size=2][b]Dim [/b]NUM [b]As Word

[/b]

[b]Input [/b]= [/size][size=2][color=#008000]PORTB[/color][/size][size=2].x



[b]Symbol [/b]LED2 = [/size][size=2][color=#008000]PORTC[/color][/size][size=2].[/size][size=2][color=#ff0000]1 [/color][/size][i][size=2][color=#000080]'FLASHING LED

[/i][/color][/size][size=2]start:

[/size][i][size=2][color=#000080]'first part of the program - adin etc.

[/i][/color][/size][size=2]



[b]Input [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x

[b]If [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x = [/size][size=2][color=#ff0000]1 [/color][/size][b][size=2]Then GoTo [/b]rest of the program

[b]DelayMS [/b][/size][size=2][color=#ff0000]5000

[/color][/size][size=2][b]If [/b][/size][size=2][color=#008000]PORTB[/color][/size][size=2].x = [/size][size=2][color=#ff0000]0 [/color][/size][b][size=2]Then GoTo [/b]delay : [b]Else GoTo [/b]rest of the program

[/size][i][size=2][color=#000080]'test if Portb.x has been low for 5 secs - if so, goto delay

[/i][/color][/size][size=2]



delay: [b]For [/b]NUM = [/size][size=2][color=#ff0000]1 [/color][/size][b][size=2]To [/b][/size][size=2][color=#ff0000]1800 [/color][/size][b][size=2]Step [/b][/size][size=2][color=#ff0000]1 [/color][/size][i][size=2][color=#000080]'30 minute delay

[/i][/color][/size][size=2][b]DelayMS [/b][/size][size=2][color=#ff0000]500

[/color][/size][size=2][b]High [/b]LED2 [/size][i][size=2][color=#000080]'not necesary but good to see if it is happening

[/i][/color][/size][size=2][b]DelayMS [/b][/size][size=2][color=#ff0000]500

[/color][/size][size=2][b]Low [/b]LED2

[b]Next

[/b][b]Sleep[/b] [/size][i][size=2][color=#000080]'do nothing else until reset or repowered

[/i][/color][/size][size=2]

[/size]

 
and here is the interuptt way
 
Code:
 
[left][size=2][size=2][color=#000000][b][size=2][color=#000000][b]INCLUDE[/b] [/color][/size][size=2][color=#0000f0]"PROTON_4.INC"[/color][/size][size=2][color=#000000]

[b]DIM[/b] RAW1 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS1 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW2 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS2 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW3 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS3 [b]AS[/b] [b]FLOAT[/b]
[b]DIM[/b] RAW4 [b]AS[/b] [b]WORD[/b]
[b]DIM[/b] VOLTS4 [b]AS[/b] [b]FLOAT[/b]

[b]Dim[/b] M_Second_Counter [b]as[/b] [b]Word[/b]
[b]Dim[/b] Second_Counter [b]as[/b] [b]Byte[/b]
[b]Dim[/b] Minute_Counter [b]as[/b] [b]Byte[/b]
[b]Dim[/b] Voltmeter_Update_Timer [b]as[/b] [b]Word[/b]

[b]SYMBOL[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] = [/color][/size][size=2][color=#008000]PortC[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] 'FLASHING LED
[b]SYMBOL[/b] QUANTA = [/color][/size][size=2][color=#ff0000]5.0[/color][/size][size=2][color=#000000] / [/color][/size][size=2][color=#ff0000]1024[/color][/size][size=2][color=#000000] ' Calculate the quantasising value

[b]INPUT[/b] [/color][/size][size=2][color=#008000]Portb[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]7[/color][/size][size=2][color=#000000] ' set it as input
[b]Output[/b] [/color][/size][b][size=2][color=#ff0000]Led1[/color][/size][/b][size=2][color=#000000] ' set it as output

[/color][/size][b][size=2][color=#800000]ADIN_RES[/color][/size][/b][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ' Set the resolution to 10
[/color][/size][b][size=2][color=#800000]ADIN_TAD[/color][/size][/b][size=2][color=#008000]FRC[/color][/size][size=2][color=#000000] ' Choose the RC osc for ADC samples
[/color][/size][b][size=2][color=#800000]ADIN_STIME[/color][/size][/b][size=2][color=#ff0000]50[/color][/size][size=2][color=#000000] ' Allow 50us for charge time

[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]200[/color][/size][size=2][color=#000000] ' Wait for PICmicro to stabilize

[/color][/size][size=2][color=#008000]TRISA[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]%00001111[/color][/size][size=2][color=#000000] ' Configure AN0 (PORTA.0) as an input
[/color][/size][size=2][color=#008000]ADCON1[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]%10001110[/color][/size][size=2][color=#000000] ' Set analogue input on PORTA (VREF RA3)
[/color][/size][b][size=2][color=#ff0000]Led1[/color][/size][/b][size=2][color=#000000]=[/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] ' LED is off

[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]Goto[/b] Start ' Jump over subrutines
'******************************************
Voltmeter:

RAW1 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000]
RAW2 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
RAW3 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]2[/color][/size][size=2][color=#000000]
RAW4 = [b]ADIN[/b] [/color][/size][size=2][color=#ff0000]3[/color][/size][size=2][color=#000000]
VOLTS1 = RAW1 * QUANTA
VOLTS2 = RAW2 * QUANTA
VOLTS3 = RAW3 * QUANTA
VOLTS4 = RAW4 * QUANTA
[b]PRINT[/b] [b]at[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[b]DEC2[/b] VOLTS1 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" V "[/color][/size][size=2][color=#000000] , [b]DEC2[/b] VOLTS2 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" V "[/color][/size][size=2][color=#000000]
[b]PRINT[/b] [b]at[/b] [/color][/size][size=2][color=#ff0000]2[/color][/size][size=2][color=#000000],[/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000],[b]DEC2[/b] VOLTS3 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" A "[/color][/size][size=2][color=#000000] , [b]DEC2[/b] VOLTS4 * [/color][/size][size=2][color=#ff0000]10[/color][/size][size=2][color=#000000] ,[/color][/size][size=2][color=#0000f0]" A "[/color][/size][size=2][color=#000000]

[b]Return[/b]
'*******************************************

START:
[b]If[/b] Voltmeter_Update_Timer = [/color][/size][size=2][color=#ff0000]500[/color][/size][size=2][color=#000000] [b]then[/b] ' check if it it is time to update the display
[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]Clear[/b] Voltmeter_Update_Timer ' reset the update timer
[b]EndIF[/b]

[b]If[/b] [/color][/size][size=2][color=#008000]PORTB[/color][/size][size=2][color=#000000].[/color][/size][size=2][color=#ff0000]7[/color][/size][size=2][color=#000000] = [/color][/size][size=2][color=#ff0000]0[/color][/size][size=2][color=#000000] [b]then[/b] ' Check the switch status if On (0)
[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
[b]Inc[/b] M_Second_Counter ' Inc the ms timer (1 ms)
[b]Inc[/b] Voltmeter_Update_Timer ' Inc the update timer (1 ms)
[b]Else[/b] ' If the switch is OFF (1)
[b]Clear[/b] M_Second_Counter ' reset M_Second_Counter
[b]Inc[/b] Voltmeter_Update_Timer ' Inc the update timer (1 ms)
[b]Endif[/b]

[b]If[/b] M_Second_Counter < [/color][/size][size=2][color=#ff0000]2500[/color][/size][size=2][color=#000000] [b]then[/b] [b]goto[/b] START 'if switch is OFF or ON for less than 5 seconds then loop
' 2500 will give you about 5 sec., 5000 about 10 sec. the figures should be tuned
' you should compensate for other instrections Execution time specially (print).

' if reached here then the switch is on for 5 seconds
' start your 30 munite timer

[b]Clear[/b] M_Second_Counter ' reset M_Second_Counter
[b]Clear[/b] Second_Counter ' reset Second_Counter
[b]Clear[/b] Minute_Counter ' reset Minute_Counter
Delay:
[b]Delayms[/b] [/color][/size][size=2][color=#ff0000]1[/color][/size][size=2][color=#000000]
[b]Inc[/b] M_Second_Counter
[b]If[/b] M_Second_Counter = [/color][/size][size=2][color=#ff0000]500[/color][/size][size=2][color=#000000] [b]then[/b] [b]Toggle[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] ' flash the LED
[b]If[/b] M_Second_Counter = [/color][/size][size=2][color=#ff0000]1000[/color][/size][size=2][color=#000000] [b]then[/b]
[b]Toggle[/b] [/color][/size][b][size=2][color=#ff0000]LED1[/color][/size][/b][size=2][color=#000000] ' flash the LED
[b]GOSUB[/b] Voltmeter ' update voltmeter display
[b]CLEAR[/b] M_Second_Counter
[b]INC[/b] Second_Counter
[b]IF[/b] Second_Counter = [/color][/size][size=2][color=#ff0000]60[/color][/size][size=2][color=#000000] [b]THEN[/b]
[b]INC[/b] Minute_Counter
[b]CLEAR[/b] Second_Counter
[b]IF[/b] Minute_Counter = [/color][/size][size=2][color=#ff0000]30[/color][/size][size=2][color=#000000] [b]THEN[/b] [b]GOTO[/b] START ' 30 min is completede go to start scanning the switch
[b]ENDIF[/b]
[b]ENDIF[/b]
[b]Goto[/b] Delay
[b]END

[/b][/color][/size][/b][/color][/size][/size][/left]
 

 
that should be a start for you
 
wizpic
Logged

When you think, "I can't do anymore. I need a break," that is the time to challenge yourself to keep going another five minutes. Those who persevere for even an extra five minutes will win in life..
kctan
Guest
« Reply #11 on: May 05, 2006, 02:08:30 14:08 »

very thanks you wizpic.
Logged
munaf
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 0
-Receive: 2


« Reply #12 on: May 08, 2006, 03:04:10 15:04 »

dear wiz Pic
 
thanks thanks
 
your's advice "Munaf If you want us to help you, you need to help yourself first," i like it.  this is  a good advice for me as like' God help them who help themselves.  i don't know any thing about pic basic.  i down load a taturial and translate dutch to english. but it was not easy to learn.
so i hope it is a taturial for me after it i will try and if i have any problam i will discus in this forum.
thanks again
Munaf
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