sub routines and procedure

General discussion on mikroBasic for AVR.
Post Reply
Author
Message
martinmc999
Posts: 31
Joined: 22 Jan 2006 10:39

sub routines and procedure

#1 Post by martinmc999 » 07 Jan 2008 19:17

In the code below have tried many different ways (byref, dim etc), but need an idiots guide to making sub routines which can be called some how, please give me an example as to how the sub should be setout, ie how should zoom_out be used?



program sony_serial_comms


dim zoomin as byte[6]

Sub zoom_in

FOR I = 0 to 5
USart1_Write_Char(zoomin)
next i
end SUB.




Sub Procedure IF_CLEAR()


USart1_Write_Char(136)
USart1_Write_Char(1)
USart1_Write_Char(0)
USart1_Write_Char(1)
USart1_Write_Char(255)
end SUB.

zoom_out:
USart1_Write_Char(129)
USart1_Write_Char(1)
USart1_Write_Char(4)
USart1_Write_Char(7)
USart1_Write_Char(3)
USart1_Write_Char(255)
end SUB.

initialize_lens:
USart1_Write_Char(129)
USart1_Write_Char(1)
USart1_Write_Char(4)
USart1_Write_Char(25)
USart1_Write_Char(1)
USart1_Write_Char(255)
end SUB.

main:

USart1_Init(9600)
Delay_ms(100)
goto if_clear
delay_ms(150)
goto initialize_lens
delay_ms(5000)
goto zoom_in
delay_ms(5000)
goto zoom_out



end.

zuran
Posts: 29
Joined: 19 Oct 2007 08:15
Location: Belgium

#2 Post by zuran » 08 Jan 2008 22:16

Code: Select all

Sub Procedure IF_CLEAR() 


USart1_Write_Char(136) 
USart1_Write_Char(1) 
USart1_Write_Char(0) 
USart1_Write_Char(1) 
USart1_Write_Char(255) 
end SUB. 
should be written as

Code: Select all

Sub Procedure IF_CLEAR


USart1_Write_Char(136) 
USart1_Write_Char(1) 
USart1_Write_Char(0) 
USart1_Write_Char(1) 
USart1_Write_Char(255) 
end SUB
so no () after procedure unles you use variables within it
and no . after end sub only after the main
and you better use USart1_Write_Char("T") or something like that instead of the char number
don't use goto, don't use zoom_out: just use procedures
and call them by their name

Code: Select all

main: 

USart1_Init(9600) 
Delay_ms(100) 
if_clear 
delay_ms(150) 
initialize_lens 
delay_ms(5000) 
zoom_in 
delay_ms(5000) 
zoom_out 



end.
regards zuran

martinmc999
Posts: 31
Joined: 22 Jan 2006 10:39

#3 Post by martinmc999 » 09 Jan 2008 09:28

THANKYOU

Post Reply

Return to “mikroBasic for AVR General”