Home

PB PICBASIC user's manual

image

Contents

1. Socket for PICBASIC for PB 3B 3H Serial LCD module port O M IP 99 O Electric power connect 9 18V DC 9 LH juu O 50000 990990 O 0 00000 20200 d 00000 P0000 D 00000 Bread board O 0000 150080 D 2 50000 1990990 g s we 002 B pg s maja aaa o wa f o 55555 59558 n Communication to PC ae Eau d Hn o o 564 25999 55999 d 3X PnP Board JN PUSH S W PIEZO e e e e 9 2222225 SG peal for testing K2K3 K7 SGN port PLAY SOUND BEEP instruction Serial Seven Segment module Switch for testing port input Photentio meter for testing A D input The following picture is RS232C circuit of PnP board gt LJ C3 CAP CAP 5 VCC CAP 3 GND X1OUT 9 6 R1OUT CAP 3 7 X1IN E lt Rx 8 5 X2IN E TX PC RS232 232 1 5 COMFILE Technology 23 PICBASIC DATABOOK The following picture is power source circuit of PICBASIC PnP board It output 5V with 9V 20V inp
2. Li 5 5 51515151515 5 Electric power o B E 9 18V DC O Him 5955799559 n Copyright 2000 COMFILE Technology B g oo g oO gt m H BERE ma 8 Alo pomo 65599 Bread board gt 2000 5 HH 0000 55555 8 E 5 5 HH Goes 155558 E E ol p E HH coeds 55555 o mi 5 5 9 E HEB Socket for PICB s BB 25559 95558 1 15 25 2 e sa BH aE 155555 5 rrj 155555 o PBM R1 R5 E E H sooo 195555 5 Alo 80508 155558 n 5 mug E E HH 2000 155556 Hd E 5 rara aras 2 z Hn oom mung d B 1 LUG amp PLAY BDARD m SGN port g s s gee Fo PIEZO h A for testing PLAY SOUND BEEP instruction Switch for testing port input Photentio meter for testing A D input Because PnP board also contains a breadboard you can add components that you want to use for testing There is unexposed wire connection inside of bread board as shown picture a y BERE 7 ma 22 COMFILE Technology PICBASIC DATABOOK The following picture describes each part of PnP board3
3. Then executes PICBASIC studio and download the following program The program will FEED BACK data from PC SET RS232 9600 DIM J AS BYTE ON RECV GOSUB 100 10 GOTO 10 100 RETURN COMFILE Technology 144 PICBASIC DATABOOK 1STOPBIT File Utility port Set cApture Printer Window Quit Baud rate Parity NON Stop bits Data bits Com_port COM1 0 0 7 777 777 7777 774 77 7777 7777 7777 77 7777 7777 7777 e 27777 777 1 7 77 777 2 777 77 7777 77 1 777 77 777 777 e 1 PICBASIC 7727 4 7 7777 777 ECHO 2 142 COMFILE Technology PICBASIC DATABOOK 0 0 0 0 94 720 0 F4 F6 2 2727427 F7 ASCII COMFILE Technology 143 PICBASIC DATABOOK Check communication port of PC 27 2 4 PICBASIC PnP Board 7 7777 1 777 L 852320 97 7 TTT 2 72723 22227 PO 7 RS22C 777 32 77 222 T L1 22 771 2 2 Tek Stop 0 00 0 0 0 NT 77 5V n A M 175 00
4. MSB LSB series DIMIAS BYTE AAS BYTE 720 Input 0 into 7 pit of Byte variable I 1 7 A2 Transmit 2 bit of variable A to 7 bit of variable PB series DIM I AS BYTE A AS BYTE 17 0 0 bit of Byte variable 17 2 Transmit 274 bit of variable A to 7 bit of variable Byte designator It is possible to access specific lower byte higher byte in Integer Long variable by using byte pointer Byte pointer is not available with Byte Single variable Byte pointers of each variable type are as follow MSB INTEGER H L LONG HH HL H L LSB Because Integer variable is 2 bytes it can be divided into H and L while Long variable can be divided into HH HL H and L due to 4 bytes DIM IAS INTEGER DIM K AS LONG 0 Input 0 into higher byte of I Integer variable 0 Input 0 into lower byte of I Integer variable K HH 0 Input 0 into higher high byte of K Long variable K HL 0 Input 0 into higher low byte of K Long variable 0 Input 0 into lower high byte of K Long variable K L 0 Input 0 into lower low byte of K Long variable PB series also use dot as byte pointer while PBM series use colon 0 L L 0 1 COMFILE Technology 41 PICBASIC DATABOOK Constant array Constant is invariant value while a program operates PICBASIC provides
5. 5 eps Read upper 4bits first and read lower 4bits For instance A is amp H41 and W is amp H57 COMFILE Technology 53 PICBASIC DATABOOK BCD Integer variable BCD value BCD conversion Value is a constant 0 65535 or a Byte Integer variable EXPLANATION This instruction converts value into BCD code BCD Binary Coded Decimal code is decimal expressed by 4bits Therefore 16bits is expressed by the four digits and 32bits by the eight digits If variable has enough size to restore the result of conversion upper value will disappear For an instance if you save BCD code 12345 into INTEGER type variable only 2345 will be saved Before BCD conversion After BCD conversion After BCD conversion Decimal Decimal Hexadecimal 1 1 15 21 amp 15 EXAMPLE DIM A AS INTEGER AS INTEGER 13 BCD A Convert value of variable A into BCD code and store the result at The result is 19 LOCATE 0 0 PRINT Display 19 the result on LCD 54 COMFILE Technology PICBASIC DATABOOK BEEP BEEP port Generate key touch sound Portis a constant 0 33 or a Byte variable EXPLANATION This instruction helps you to generate key touch sound simply Connect one of PICBASIC ports to PIEZO and use the instruction to generate sound which will be generated around 2KHz f
6. 2 Res Rss TC 3 eo Gun ST S S 6 10202 8 9 os Ps TL 100 os Pose TL uo TL 2 uo Pas 4 fon Pan Bok sr voz Po Boa s 7 os Pas Boa s 4 von Poss Boa sr vos Pos Boa sr 20 vos Poe s 21 uo Pott sr 2 vos Pos s vos Poa 24 joo s 2 on s 2 voz Pozz s 2 o3 s 3 fon 156 3 Picsus copot CT 333 ne Cd 12 COMFILE Technology PICBASIC DATABOOK 9 45V U3 Ai cer E in VSS SDA D2 24LCXX 48V 1N4148 R R6 R4 m RES B7 PO B6 58 B lt J B P2 B4 E e B3 3 lt E E Bs 9 PA 3 2 3 46 Q lt 32 25 P26 gt 23 bec gt 124 22 e E FP DOORS 23S P12 paz 35 lt 18 PIC16C74A 04 PQ CAP NP CAP NP GND COMFILE Technology 13 PICBASIC DATABOOK PB 3B RES PCOUT 1 00 ADO PCIN I O1 AD1 PICBUS 02 2 107 1 03 AD3 06 CLKIN 05 1 04 AD4 1017 GND 1016 OSCIN 5V OSCOUT GND 1 08 O15 l O9 PWMO 014
7. 232 PC LL PICBASIC 7 7 27777 12V 1 22Kohm to WO PIN lt GND PC RS232C PORT DB 9 Mail Connector Side COMFILE Technology 147 PICBASIC DATABOOK MEMO 148 COMFILE Technology
8. Convert into Integer type Fem CLNG Convert into Long type Fem CSNG Convert into Single type Other instructions RND Generate random value TABLE Transform a table by parameter ON GOTO branch by parameter ON GOSUB Execute subroutine by parameter BREAK Generate break COUNT Read value of count from CLKIN terminal PEEK Read content of specific address RAM on main microprocessor POKE Change content of specific address RAM on main microprocessor RESET Reset DELAY Set 1 65535 mS of delay CAPTURE Measure cycle of outer wave 48 COMFILE Technology PICBASIC DATABOOK ABS Single variable ABS value Absolute value Value is Single constant variable EXPLANATION This instruction returns the absolute value of an input value The input value must be a Single constant variable If input value is not Single type you should convert the value into Single type by CSNG instruction before using this instruction EXAMPLE DIM F1 AS SINGLE DIM F2 AS SINGLE F2 1234 5678 F1 ABS F2 1234 5678 is saved at F1 Because that Byte Integer variable is not singed value there is no need of ABS instruction on those two types of variable However because Long variable is singed variable it should be used as the following example F1 CSNG L1 Execute CSNG instruction first F1 ABS F1 Execute ABS instruction L1 CLNG F1 Execute CLNG instruction means the result of this instruction becomes Sin
9. EEWRITE EEWRITE address data byte EEWRITE address data Read from EEPROM Address is a Byte Integer constant 0 amp HFFFF variable Data is a constant 0 255 or a Byte variable Byte is a constant 0 255 or a Byte variable indicating how many bytes will be written EXPLANATION This instruction writes assigned bytes of data at assigned address of EEPROM Data is byte constant variable When you use EEWRITE instruction in PBM series you can assign how many bytes will be written at EEPROM When variable is omitted it is 1 EXAMPLE DIM AS BYTE DIM ST AS STRING 16 EEWRITE 0 Write value of at address 0 EEWRITE 0 ST 18 Write eighteen bytes of String variable ST at address 0 The actual length of sting area is added to maximum length Actual length maximum length 2 ADDITIONAL DESCRIPTION ABOUT EEREAD amp EEWRITE In PICBASIC EEPROM or Flash memory is mainly used to store programs If you do not use up all of the memory space for program you can use the rest of the EEPROM space by EEWRITE EEREAD instructions Most of cases EEPROM is not entirely filled with program Because storing program starts from lower addresses higher addresses could remains unused Because 4Kbytes of program memory in PB 3X 1S is O amp HFFF and a program will be written from address 0 you should write data from amp HFFF reversely EEWRITE amp HFFF R1 EEWRITE amp HFFE R2 EEWRITE amp HFFD R3 R1 EEREAD amp HFFF R2
10. 2 PB 3B 3H PBM R1 R5 Maximum capturing range 1 3sec 0 26sec 0 26sec 04sec Retum value Captured interval 20 Captured interval 4 Captured interval 4 Captured interval 7 60 COMFILE Technology PICBASIC DATABOOK CHR String variable CHR value Convert ASCII code into character Value is a constant 0 255 or a Byte variable EXPLANATION This instruction converts ASCII code into a corresponding character For instance CHR amp H41 returns EXAMPLE DIM ST AS STRING 16 Define 16 as the maximum size of String variable ST ST CHR amp H41 A is stored at ST Refer to ASCII code table in description of ASC instruction CINT Integer variable CINT value Convert Single type into Integer type Value is a Single constant variable EXPLANATION This instruction converts Single variables constants into 16bit Integer variables constants EXAMPLE DIM L1 AS INTEGER DIM S1 AS SINGLE 1 1234 5678 CINT S1 COMFILE Technology 61 PICBASIC DATABOOK CLNG Long variable CLNG value Convert Single type into Long type Value is a Single constant variable EXPLANATION This instruction converts Single constants variables into 32bits Long constants variable Digits beyond point are cut EXAMPLE DIM L1 AS LONG DIM 1 AS SINGLE 1 1234 5678 CLNG S1 1234 is stored at L1 CONST DEVICE CONST DEVICE device Declare device
11. 5 Wo ego rior Pas Cs o Pa R o Pur j es 1 vs Pa cs be T R se PON PP Cd onno PB 3H module is same as PIC16c74 PICmicro in pin layout The following picture is a basic circuit to operate PB 3H module 5V RES I O0 AD0 I O1 AD1 PICBUS 10K 1N4148 02 2 028 1 03 AD3 1 027 CLKIN 1 026 l O4 AD4 025 5V l O5 AD5 1 024 T iss 5V 0 tuF H l O7 AD7 5V 1 023 22 GND 022 2 OSCIN 021 25 OSCOUT 1 020 1 08 1 015 l O9 PWMO 014 PRINTER PORT I O10 PWM1 1 013 1 011 1 012 1 016 1 019 1 017 1 018 COMFILE Technology 17 PICBASIC DATABOOK PBM R1 R5 40 RES e 2 39 PICBUS GND e 3 Single Board Computer 38 e l O33 ADCHI YOO ADD 4 37 1 032 ADCHO YO1 AD1 5 36 e 1 031 02 02 6 35 1 030 YO3 AD3 e 7 34 e 1029 YO4 AD4 8 33 e 1 028 VO5 AD5 e 9 32 1 027 JO6 AD6 10 31 1 026 YO7 AD7 11 30 1025 1 08 INT 12 Flash 64K RAM 32K EEPROM 32K 12bit ADC RTC 34 I O 29 e 1 024 9 e 13 28 e 1 023 10 1 14 85 178215 27 1022 yon 15 26 021 012 16 25 1020 1013 17 24 1019 yO14 1X e 18 23 018 JO15 RX e 19 22 017 CLKIN 20 TECHNOLOGY 2 1
12. 55 45 20 32 23 800 12 2 54 100 10 40 64 1600 40 45 COMFILE Technology PICBASIC DATABOOK PB 3X 15 8mm 8 3mm A 2 54mm 35 1mm 52 2 yY PBM Rx 75 4MM lt TM u Single Board Computer 5 e e e E e e E 0 o e LO Flash 64K RAM 32K EEPROM 32K 12bit ADC RTC 34 I O e COMFILE gt 2 54mm 100mil TECHNOLOGY 4 66mm 2600 mil COMFILE Technology 21 PICBASIC DATABOOK PICBASIC PNP BOARD PnP board is an educational board for testing training PICBASIC without soldering There are two types of PnP boards PnP board for PB 1X PB 2X PBM RX modules and PnP board3 for PB 3X modules PnP board contains a basic power source circuit S W input circuits LED output circuits a RS232C level conversion circuit and a breadboard etc The following picture shows each parts of PnP board RS232C LED for testing port output Serial LCD module port Communication to PC O Q
13. ADDITIONAL INFORMATION You need to organize 1 10 of extra circuits so that you use ADKEYIN instruction With the instruction you can receive a number of key input through only few ports When there are eight of A D ports you can receive 80 of key inputs at most ADKEYIN instruction is not available at 12bit A D ports When symptoms such as incomplete key input improper recognition of key input and etc occur adjust resistor s value 100K Because the symptoms are caused from A D conversion error by influence of noise etc they could be resolved by adjusting value of pull up resistor 52 COMFILE Technology PICBASIC DATABOOK ASC Integer variable ASC character ASCII code of character Value is a character Character is surrounded by mark Example is A or a Sting variable EXPLANATION This instruction returns ASCII code of the first character in a string EXAMPLE DIM ST AS STRING 16 Set 16 as maximum length of string DIM I AS BYTE ST ASC ST amp H41 which is ASCII code of A is stored at variable The following table shows ASCII code wo Oe 1 amp J sys etes f7 a o lt gt ee ede x Y z t 1jJ s gt e spp
14. DIM INT EN AS BYTE Declare interrupt enable flag INT EN 0 Enable state ON TIMER 0 GOSUB 100 When occurring timer interrupt line 100 executes GOTO 10 Main loop 100 IF INT_EN 1 THEN RETURN When a interrupt enable flag is 1 the interrupt is skipped RETURN End of interrupt routine In above example if some other routine made INT_EN 1 the interrupt routine at line 100 will not execute 118 COMFILE Technology PICBASIC DATABOOK SET PICBUS SET PICBUS HIGHILOW Set transmission speed of PICBASIC EXPLANATION This instruction adjusts transmission speed of LCD output port PICBUS Initial value is set 19200 baud rate To change into 4800 baud rate use SET PICBUS LOW To retum 19299 baud rate use SET PICBUS HIGH All serial LCD modules have a jumper adjusting baud rate To display characters on LCD properly parameter of SET PICBUS instruction must coincide with baud rate adjusted by jumper in LCD CAUTION The initial baud rate of all PICBASIC models having firmware v 27 or higher is 19200 All serial LCD modules provided by Comfile Technology inc has 19200 of initial baud rate COMFILE Technology 119 PICBASIC DATABOOK SET RS232 SET RS232 baud rate Declare RS232C communication Baud rate is fixed value EXPLANATION This instruction is used to declare use of RS232 hardware In order to use GET or PUT instruction you must use this instruction in the first part of program Once SET RS232 is activ
15. Display I The following example is a program outputting result of RND by sound If you connect port2 to PIEZO you can listen funny sound DIM J AS BYTE 10 J RND 0 Store random number into J SOUND 2 J 3 Output sound pulse having J as a tone GOTO 10 COMFILE Technology 111 PICBASIC DATABOOK SERIN SERIN port speed mode delay label control statement variable Receive RS232C Port is a constant or a Byte variable specifying port number to receive RS232 PBM series can use only port0 15 Speed is a constant specifying transmission speed of RS232C It could be different in according to baud rate Mode is a constant 0 or 1 indicating to invert PWM If mode is 0 PWM is not inverted Otherwise PWM is inverted Delay is a constant or a Integer variable specifying latency time for input If receiving RS232C does not finish within delay time program jumps to the error routine label Otherwise it proceeds to next line Label is a label line where to be jump when latency for input exceeds delay Control statement specifies control option for receiving RS232C such as WAIT UNTL and SKIP UNTL and SKIP are not available in PBM series Variable is a Byte variable array or a String variable specifying where received data is stored in EXPLANATION This instruction receives data through RS232C by software You can freely use ports and delay Received data will be stored at a receiving variable Transmission format of RS
16. EEREAD amp HFFE R3 EEREAD amp HFFD At this moment you must not let one of them overlap with the other program area and data area If it happens unpredictable result may occur Therefore when you use EEWRITE and you should always make sure of the highest address of program The highest address of program will be displayed at lower part of screen as Code Size XXX byte right after downloading PB 1B PB 1S 3B 3H 25 2 0 amp H7FF 2 0 amp 4 0 amp H1FFF 8K 0 amp H3FFF 16K Because PBM series modules have extra EEPROM space for EEWRITE and EEREAD you do not have to worry about the overlap and can use memory from address 0 Extra EEPROM space EEWRITE amp R1 PBM R1 EBNERS EEWRITE amp H1 R2 o aHtFFF BQ 0 amp 32K EEWRITE amp H2 R3 COMFILE Technology 71 PICBASIC DATABOOK EPADIN Integer variable EPADIN row column Keypad input Row is number of rows from four to 8 N A with variables Column is number of columns from 4 to 8 N A with variables EXPLANATION This instruction is able to read key matrix up to 8x8 by using ports 16 31 Number of rows and columns are adjustable If there is no key input then it returns 0 If some it retums scan code of corresponding key Keypad circuit must be organized as the following picture so that ports from 16 to 23 are output por
17. PLAY PLAY port data Play music Port is a constant 0 31 or a Byte variable indicating port number EXPLANATION This instruction plays simple melody A appropriate port should be connected to a PIEZO or a speaker PBM series can use only 0 15 ports for play The followings are how to make data Di Ad C D b 44 4422 3 4 5 6 7 WHEN DATA IS 4 Two parameters are used to express one tone One is an alphabet A G determining interval of the tone and the other is number determining length of the tone Therefore C4 means Do of quarter note WHEN DATA IS 5 One tone be expressed by four parameter at most means higher tone by one semitone and means higher tone by one octave Therefore C 5 means a tone is higher tone than Do by one semitone and one octave Its length is 5 Quarter note C5E5G5 C1 Play do mi sol do EXAMPLE PLAY 1 C5C7D4C4F4E2C5C7D4C4G4F2C5C7 C4A4F4E4D2A 5A 7 PLAY 1 G4E6E6G6E6C4D4E6D6CE6E6G4 C5G7 C5G7 C6G6E4G4D6 PLAY 1 C9D9E9F9G9 Output to port1 104 COMFILE Technology PICBASIC DATABOOK PRINT PRINT string value1 value2 Display on LCD String is a String like String variable is available in PBM series Value is a constant 0 255 or a Byte variable EXPLANATION This instruction displays characters and digits on a LCD When you input values the corresponding ASCII codes will be disp
18. Port 5 Block 0 6 Port 6 Block 0 1 2 3 4 5 6 7 8 9 10 11 VO 7 Port 7 Block 0 1 0 8 Port 8 Block 1 9 PWMO Port 9 Block 1 10 PWM1 Port 10 Block 1 011 Port 11 1 12 Port 12 Block 1 13 Port 13 Block 1 14 14 1 15 15 1 CLKIN Counter input PICBUS e ST Schmitt trigger TTL TTL Level input LCD port TTL Level input port recognizes the state of a pin as HIGH above 1 4V while as LOW below 1 3V Schmitt trigger input port recognizes the state of a pin as HIGH above 3 4V while as LOW below 3 3V 10 COMFILE Technology PICBASIC DATABOOK 5V O U CONS 2 SCL VSS SDA 45V 5V 24LCXX Q O R5 D1 R2 U2 R 1N4148 10K Rs 354 27 COSH lt lt T P2 S PRINT SM E 2 p 9 20 19 11 u P15 S lt PFP SE RC3 RC4 lt JP12 lt 11 PIC16C73A 04 SO S JP10 lt 9 5V forem C4 CAPNP CAPNP GND COMFILE Technology 11 PICBASIC DATABOOK 45V 1 N C RES 2 N C GND 3 PICBUS 0 0 4 CLKIN 1 01 AD1 5 1 026 AD7 1 02 AD2 6 uU l O25 ADG I O3 AD3 7 N 1 024 AD5 1 04 AD4 8 o 1 023 1 05 1 022 1 06 NN 1 021 1 07 1 020 1 08 N 1019 l O9 PWMO 1 018 1 010 PWM1 1 017 1011 1 016 1 012 1 015 1 013 1 014
19. 010 1 O13 1 011 012 Reset 2 3 ir Pr 4 o Pez An s Peta s cuma o 7 woe Tn AD s oon waoe o we r sr Ca won sr v2 sr Ce om P sr wu Pt sr wo P sr sx 9mm T 1 wo sr m wy Pur sr Ca ws P Ca we P sr wr Pes tomi T RJ x PON Poeno _ 14 COMFILE Technology PICBASIC DATABOOK All pins except Vss and RESET pin is used for I O O ports are arranged in order of their number and are blocked by eight ports The blocked eight ports is called Port block Port block is essential to process by byte Generally RES pin is connected with Internal RESET delay circuit Because CLKIN pin can detect Rising edge even 20KHz of high speed pulse can be counted PB 3B module is same as PlCmicro PIC16C73 in PIN layout PB 3B module has one port block Addressing at port block 0 or 2 is ignored by i
20. EXPLANATION This instruction cut a string from left as much as specified value EXAMPLE DIM ST AS STRING 16 Set 16 as the maximum length of string DIM RE AS STRING 16 ST LOVE YOU LEFT ST 5 LOCATE 0 0 PRINT RE LCD displays I LOVE COMFILE Technology 87 PICBASIC DATABOOK LEN Integer variable LEN string Length of string Sting is a String variable EXPLANATION This instruction returns real length of string EXAMPLE DIM ST AS STRING 16 Set 16 as the maximum length of string DIM AS INTEGER ST COMFILE LEN ST Result of is 7 88 COMFILE Technology PICBASIC DATABOOK LOCATE LOCATE X coordinate Y coordinate Appoint position of display X coordinate is a constant 0 255 or a Byte variable Y coordinate is a constant 0 255 or Byte variable EXPLANATION This instruction appoints position of display on LCD Coordinates of the left top position on LCD is 0 0 The maximum size of coordinates is different in accordance with LCD models In case of 16X2 LCD you can use 0 15 of X coordinate and 0 10f Y coordinate Display at 10 0 0 1 EXAMPLE LOCATE 10 0 PRINT ABC COMFILE Technology 89 PICBASIC DATABOOK LOG FETI Single variable LOG value Logarithmic function Value is a Single constant variable EXPLANATION This instruction returns the lo
21. 1 or 9200 2400 115200 Receiving buffer N A Available PBM has built in 96 bytes of receiving buffer Receiving interrupt N A Available Duplex Half duplex Full duplex Signal level Invert non invert N A WAIT character receiving control Available up to 2 bytes N A by software Model PB series PBM series PBM series The most significant strong point of SERIN SEROUT instruction is free to select port and uses several ports simultaneously On the other hand GET PUT instruction can use only port 14 15 SERIN SEROUT Printer PICBASIC BN x GET PUT Single Board Computer PICBASIC i Display Haro ERE H SS The most strong point of GET instruction is receipt of data during other instructions SERIN cannot receive data during other instruction 134 COMFILE Technology PICBASIC DATABOOK Basic of RS232C There are two kinds of serial communication Asynchronous and Synchronous Synchronous communication needs another clock signal to synchronization between a transmitter and a receiver SHIFTIN SHIFTOUT instruction of PICBASIC is used for the synchronizing communication Because that RS232C is asynchronous communication there is no need of clock signal Instead of that RS232C communication needs synchronization of baud rate between a transmitter and a receiver transmitter sends data at appointed baud
22. AD7 10bit 8 channel 1 2 3 4 5 6 7 8 9 10bit 8 channel COMFILE Technology 00 0 1 1 1 02 AD2 1 03 AD3 04 4 1 05 5 1 06 AD6 07 AD7 00 I O1 AD1 l O2 AD2 04 4 1 2 3 4 5 6 1 8 026 7 025 024 5 8bit 8 channel 00 lI O1 AD1 02 2 1 04 AD4 10bit 5 channel d 8d O Q Q N B oo s o gt Q N 12 T Single Board Computer 39 die Flash 64K RAM 32K EEPROM 32K 12bit ADC RTC 34 2000 gt gt TECHNOLOGY 21 033 1 l O32 ADCHO 12bit 2 channel 51 PICBASIC DATABOOK ADKEYIN Integer variable ADKEYIN port conversion key input Port is a Byte variable 0 33 or a port number acceptable A D input EXPLANATION This instruction receives key inputs using A D conversion function Port must be able to receive A D input In the following circuit OV is inputted on pushing the first key 500mV is inputted on pushing the second key 800mvV is inputted on pushing the third key When all key is released 5V is inputted One A D input port can receive up to ten key inputs at most by using ADKEYIN instruction EXAMPLE ADKEYIN 5V ir 100K 40K 10K 10K az 10 ADKEYIN 0 Receive A D key input at port 0 PRINT Display key value on LCD GOTO 10
23. D 120 D 0 Chi X 2 60 s NN 27 772 717 77 7777 F4 PC RS232 9 PIN 330ohm 1 6 RD2 7 TD 3 4 8 GND 5 9 LED 77717 77777 277 1 77 7777 pi TTTTT 22 T 922 912 2 22 2 2 1 144 COMFILE Technology PICBASIC DATABOOK GET P3373 l AB 7 107 1 _ 12 1 B9876543210_ TX eu RM COUNT TX COUNT 19 58 52 NON 8 RSCII SET RS232 9600 RS2320 DIM AS BYTE DIM A 12 AS BYTE ON RECV GOSUB 100 277 7077 1007 77 10 10 77777 77777 77 100 DELAY 10 777 2 77777 7777 11 427 777 27 GET 4272 D 7777 LOCATE 1 1 PRINT CHR A I LCD 0 77 NEXT I RETURN COMFILE Technology 145 PICBASIC DATABOOK AB9876543210 VkL DELAY 10 1 LL ON 777 777 77 92777 777777 77 77 272 A 2 927237 T 1007 277 PEL A T7 77 GET 277 DELAY 10 10mB 2 2 7 1 777 FOR NEXT 277 GET 777 lt 918176
24. Device could be one of 1B 1S 2S 2H R1 and R5 Use last two digit of model name EXPLANATION This instruction is used to declare a kind of PICBASIC module at the first part of program EXAMPLE CONST DEVICE Use module 62 COMFILE Technology PICBASIC DATABOOK COS FETI Single variable COS value Compute COSINE value Value is a Single constant variable EXPLANATION This instruction returns COSINE value of value Angle by radian Value must be SINGLE type If value is not Single type you must convert it into Single type by CSNG instruction EXAMPLE DIM F1 AS SINGLE F1 COS 1 0 COUNT Integer variable COUNT parameter Count input Parameter is a constant 0 or 1 and is not available with variable 0 sustain 1 clear EXPLANATION This instruction returns the result of pulse count from CLKIN terminal The count value of CLKIN terminal is counted by a hardware circuit and is sustained internally The instruction returns counted value If parameter is 0 the instruction keeps current count value If parameter is 1 the instruction clears the count value Because size of internal counter is 16bits the maximum countable number is up to 65535 Therefore when count value is excess the 65535 it rolls over to zero EXAMPLE COUNT 1 Transmit the result of count to and clear count value 0 Transmit the result of count to and keep count value The followin
25. IF lt 10 THEN J ADIN 0 smaller than 10 ELSEIF lt 80 THEN There must be no space between ELSE and IF like ELSEIF J ADIN 1 If is smaller than 80 ELSE J ADIN 2 other cases END IF CONDITIONAL EXPRESSION Conditional expression variable compare operator variable constant logic operator Compare operator gt Logic operator AND OR CAUTION 1 When using IF statement laying two or more conditions continuously by using brackets is not available For an example if there is a conditional statement as follows IF A gt 1 AND lt 10 OR B gt 10 AND B lt 20 THEN K K 1 END IF As a processor does not recognize brackets above conditional statement will be operated just like the followings IF gt 1 lt 10 ORB gt 10 AND lt 20 THEN K K 1 END IF 82 COMFILE Technology PICBASIC DATABOOK Therefore the first conditional statement will end in different value from desired result In this case the conditional statement must be separated two IF statements IF gt 1 ANDA lt 10 THEN 1 END IF IF B 10 AND B 20 THEN K K 1 END IF CAUTION 2 Operation of comparison must be performed with same data type SINGLE type must be compared with SINGLE type When comparing INTEGER type data BYTE INTEGER LONG with SINGLE type data the INTEGER type data must be converted into SINGLE type by CSNG instruction IF F1 lt CSNG I1 THE
26. Some of those registers are out of control by PICBASIC PEEK and POKE instruction allow you to access those registers EXAMPLE PEEK amp H85 Read the content of register amp H85 Read the PORTA state of register amp H85 COMFILE Technology 101 PICBASIC DATABOOK POKE POKE file register value Write file register File register is a file register number 0 amp HFF Not available with variable Value is a constant 90 255 or Byte variable EXPLANATION This instruction writes value directly into a file register of MCU You can find various registers in File Register Map refer to data book which can be accessed by PEEK and POKE instruction EXAMPLE POKE amp h5 0 Clear register amp H5 Register amp H5 accesses PORTA ADDITIONAL INFORMATION Because that PEEK and POKE instruction could take critical effect on PICBASIC hardware if you are not well used in controlling PIC16F87X don t try it 102 COMFILE Technology PICBASIC DATABOOK POW Single variable POW value X value Y X value Value X and Value Y are a Single constant variable EXPLANATION This instruction calculates a value of X Value X and value Y must be single constants or variables If they are not single type you should convert them into single type with CSNG instruction as the following example EXAMPLE DIM F1 AS SINGLE F1 POW 2 0 3 0 8 0 is inputted into F1 COMFILE Technology 103 PICBASIC DATABOOK
27. TIMEOUT RETURN When falling edge Start bit of RS232C at port 5 is detected a program is stop its current execution and jumps to RS232_INT routine to wait for RS232C transmission In this moment make certain that the first data can not received Because it takes a couple of mS for PICBASIC modules to detect the edge and jump to SERIN instruction Therefore a data sender had better send dummy data 00 as the first data COMFILE Technology 113 PICBASIC DATABOOK SEROUT SEROUT port speed mode interval data RS232C transmission Port is a constant or a Byte variable specifying port number to receive RS232 PBM series can use only port0 15 Speed is a constant specifying transmission speed of RS232C It could be different in according to baud rate Mode is a constant 0 or 1 indicating to invert PWM If mode is 0 PWM is not inverted Otherwise PWM is inverted Interval is a constant specifying space between bytes by mS Data is a Byte constant variable or a string variable EXPLANATION This instruction outputs RS232C data controlled by software Transmission format 8bits none parity and one stop bit is fixed You can set ports output state freely and do inverting output Data can be string ASCII code constant and variable etc M SEROUT 3 66 0 D A The data must be byte type If integer or long type data is transmitted only lower 8bits will be sent You can not use single type data in SEROUT The fol
28. a function allowing user to definite constants like array This function is very useful to handling a lot of data You can use data defined as constant array as array in program The following example shows how to definite use constant array CONST BYTE DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 120 DATA Return 31 1 1 1 DATA Return 25 Other data type of constant array is also available CONST INTEGER 6000 3000 65500 0 3200 CONST LONG 12345678 356789 165500 0 0 CONST SINGLE DATAS 3 14 0 12345 1 5443 0 0 32 0 You can extend data used for constant array in several lines CONST BYTE DATA 31 25 102 34 1 0 0 0 0 0 65 64 34 12 123 94 200 0 123 44 39 120 239 132 13 34 20 101 123 44 39 12 39 You can use string data as constant array CONST BYTE I LOVE PICBASIC 2000 13 10 0 The difference between general array and constant array is that data defined as constant array shall be recorded in program memory when it is downloaded into a PICBASIC module General array is recorded in data memory SRAM and is not conserved after RESET But constant array remains in program memory even after RESET Content Array Constant array Storage Data memory SRAM Program memory FLASH Record In operation In downloading Modification during operation Available N A Used for Storing variant data Storing
29. bit A D 2channel PWM channel 2 2 2 2 2 2 2 2 Resolution 8bit 8bit 8bit 10bit 10bit String N A N A N A N A N A N A Available Available 32bit integer N A N A N A N A N A N A Available Available real number RS232 buffering N A N A N A N A N A N A Available Available method Execution rate comparison is execution speed of each PICBASIC module compared with the fastest module PB 3X i e PB 1B is slower than PB 3X as much as 13 1 times The larger execution rate is the slower execution speed is Memory access is a method of accessing the program memory at CPU Parallel access is faster than Serial access Because a PB 3X module uses a built in BUS it is much faster than PBM Rx modules COMFILE Technology 9 PICBASIC DATABOOK PINOUT amp CIRCUIT PB 1B 1S module 5V PB 1B 1S 1 013 17 1 014 18 CLKIN 20 PICBUS 21 08 12 V 1 RES 2 GND 3 Cc 9 06 10 l O9 PWMO 13 I O10 PWM1 14 1 011 15 1 07 1 015 04 AD4 8 1 05 1 012 Description Port block Power 5V Function IRES Reset 5V GND Ground 1 00 ADO Port 0 Block 0 AD input 1 AD1 Port 1 Block 0 AD input I O 2 AD2 Port 2 Block 0 AD input 3 AD3 Port 3 Block 0 AD input 4 AD4 Port 4 Block 0 AD input 5
30. invariant data such as constant After RESET Initialization Conserved 42 COMFILE Technology PICBASIC DATABOOK Expression Expression in PICBASIC forms as follows 1 0 Input 0 to variable 1 1 1 Increase variable by 1 I2J 12 K Multiply variable J by 12 and divide by variable K PBM series can execute Integer number and floating point number operation Operation with each types of variable must be done with corresponding variables and constants For instance Integer operation must consist of Integer variables and constants If you want to use an Integer variable in floating point number operation you should convert the Integer variable into a Single variable by CSNG instruction DIM 51 AS SINGLE DIM IAS LONG 1 1 1 Valid expression 1 1 1 0 Invalid expression All constant in floating point expression must have point 1 1 1 Invalid expression Used Integer variable and Single variable together 1 1 CSNG I Valid expression Used CSNG instruction for converting variable type All Integer operations proceed internally with Long type data The result of an operation is converted into the form of destination variable and is stored at a destination variable For instance if a destination variable is Byte variable the result of an operation is stored in the form of Byte type even though the result exceeds 255 Make sure that value exceeding 8bits is cut DIM IA
31. is called Port block Port block is essential to process by byte Generally RES pin is connected with Vpp Internal RESET delay circuit port 32 33 are dedicated to AD input they have no other function except AD input Pin 40 Vss is backup power for Real time clock PICBASIC modules contain 0 1F super condenser It is charged while the module is supplied electric power When power source of the module is off it starts working as battery If you keep the PICBASIC module off during over 6months you should need to supply extra electric power to the PICBASIC module through Pin no 40 so that internal clock keeps working Because CLKIN port can detect Rising edge even 20KHz of high speed pulse can be counted PBM R1 is same as PBM R5 in function except 12bit A D function and real time clock function ELECTRIC CHARACTERISTIC OF PBM RX Vbo Voltage 4 5 5 5 Current consumption PB 1B 15 25 7mA PB 2H 15mA PBM R1 R5 50mA Storage temperature 40 125 Operating temperature 10 75 Source current of port 25mA Sink current of port 25mA Maximum allowable current of Vas 300mA Maximum allowable current of Voo 250mA COMFILE Technology 19 PICBASIC DATABOOK DIMENSION PB 1B PB 1S PB 2S PB 2H 20 Oo nnnnannnonnnnannnmnnpm 2 54 100 50 8 2000 402 J
32. mode is available in PB series Step Into Step Over Step Out Modify Variable Erase Flash Exit COMFILE Technology 35 PICBASIC DATABOOK You can modify value of specific variable in the Modify Variable box shown as below Modify Variable Variable New Value Ok Cancel CHECKING VARIABLE IN OPERATION This function is available in only PBM series When you use PB series it is not activated This function allows you to check or modify value of specific variable When you click Check Variable in the Run menu current values of all variables are displayed on window Studio dmy docurmentswtestl bas 1 File Edit Search Run Setup Help Bun Fb Break F6 01 CONST DE d i SET nRs2 88 S DIM J View Object Code F8 ON View Label List i GC View PICBASIC Flash Memory i00 GE Check Variable PL Modify Variable Clear Flash Memory 36 COMFILE Technology PICBASIC DATABOOK Chapter 2 Instructions 38 CBASIC DATABOOK General rule of instructions Rule of instruction in PICBASIC language is very similar with BASIC language Instructions can be classified as commands and functions A function is used as part of a expression and has round bracket at a instruction s tail Command PRINT GOTO RETURN Function ADIN 0 EEREAD O lt Functions have round brackets at the e
33. rate a receiver deal with data of the baud rate Asynchronous Synchronous CLK BE TE EM MINA o ee Data of RS232C is composed of one START bit eight DATA bit and one STOP bit This composition is called a protocol of 8BIT NONE parity 1STOP bit is also expressed with abbreviated form 8 N 1 In addition there is another protocol composed of seven DATA bits ODD parity and two STOP bits However PICBASIC is designed to use only 8BIT NONE parity 1STOP bit protocol which is most commonly used The following picture shows RS232C format composing one set of DATA The format in the picture is LSB FIRST because that data transmission starts with lower bits A amp D N y i A COMFILE Technology 135 PICBASIC DATABOOK In RS232C communication a sender only has to output data in the forms as above picture at appointed baud rate However a receiver should do work that is much more complicated At first the receiver should detect START bit above all Once after detecting falling edge of START bit it starts sampling DATA bits at appointed interval in accordance with appointed baud rate Receiving one set of DATA is finished by combining HIGH or LOW status of DATA bits incoming through a receiving port y v 4 N C A amp A KR A o 9 6 384 Baudrate The following picture expresses waveform of actual data tra
34. space Instruction Result PRINT FLOAT SN bbbb1234 56789 PRINT FLOAT SN 4 1234 5678 PRINT FLOAT SN 4 2 1234 56 PRINT FLOAT SN 2 2 34 56 To express a Byte Integer Long value in forms of Single value having point you must execute conversion by CSNG instruction DIM A AS INTEGER DIM SN AS SINGLE A 123456 SN CSNG A Convert into SINGLE type by CSNG instruction PRINT FLOAT SN 6 5 LCD displays 123456 00000 CAUTION There is possibility of errors in process of FLOAT instruction converting a Single value into String For instance when an actual stored value is 4 0 FLOAT instruction could express the value 3 999999 This is caused that PlCmicro main processor of PICBASIC modules cannot perfectly completes Floating point number conversion of IEEE 745 due to its limitation of hardware i e the actual stored value is 4 0 It is just expressed 3 999999 when it is converted into string by FLOAT instruction 76 COMFILE Technology PICBASIC DATABOOK FOR NEXT FOR variable1 7start TO end STEP increment NEXT variable2 FOR NEXT loop Variable is a Byte Integer Long variable Start value is a Byte Integer Long constant variable specifying the initial value of variable Increment is a Byte constant 128 127 variable indicating variation of variable1 EXPLANATION This instruction sets variable as start value and repeats commands instructions between FOR and NEXT until the varia
35. the maximum byte The other byte is for NULL value indicating end of string P CIBI ASI C2000 14 0 Garbage In the above picture PICBASIC2000 12bytes of string data is stored in 14bytes of memory space In this case the rest 2bytes is filled with unknown garbage value DIM ST AS STRING 16 Declare ST as string variable with 16byte of maximum bytes ST COMFILE TECHNOLOGY Because data COMFILE TECHNOLOGY is out of Reserved range 16bytes last two characters GY will Not be stored COMFILE Technology 39 PICBASIC DATABOOK As above example shows because string variable cannot contain data exceeding maximum bytes you should be prudently determine the maximum bytes Using you can bind strings When you bind strings you make certain that the result string must have larger bytes than sum bytes of combined strings SG SG ST Bind strings CAUTION All types of variable of PBM series will not be initialized to specific value on RESET while that of PB series is initialized Therefore when you work with PBM series you had better definite initial value of variables clearly before using them Defining constant Sometimes it is convenient for maintaining a program to express numbers in characters Therefore PICBASIC language provides an instruction CONST for that CONST RELAYPORT 5 Hereafter RELAYPORT is substituted
36. the result of instructions including DEC when variable A has 12345 b is space Instruction Result PRINT DEC A 12345 PRINT DEC A 10 bbbbb12345 PRINT DEC A 10 0 0000012345 PRINT DEC A 3 345 PBM series can store the result of DEC instruction in a String variable as follow DIM ST AS STRING 16 Declare 16 the maximum length of string DIM AS INTEGER 1234 ST 5678 Conjunct strings result 12345678 is stored at ST COMFILE Technology 69 PICBASIC DATABOOK EEREAD Integer variable EEREAD address byte Integer variable EEREAD address Read from EEPROM Address is a Byte Integer constant 0 amp HFFFF variable Byte is a constant 0 255 or a Byte variable and is used to assign how many bytes will be read EXPLANATION This instruction reads assigned bytes of data from assigned address of EEPROM Because EEPROM can retain its contents after RESET it is normally used to save user s data When you use EEREAD instruction in PBM series you can assign how many bytes will be read from EEPROM Default value of byte is 1 EXAMPLE DIMIAS BYTE DIM J AS INTEGER DIM ST AS STRING 16 EEREAD amp HFFF Read a byte from FFFH and store at J EEREAD amp HFO00 2 Read two bytes from FOOH and store at J ST EEREAD amp HFO00 18 Read eighteen bytes from store at string variable ST 70 COMFILE Technology PICBASIC DATABOOK
37. works except sending data it is hard to watch the Flow control pin all the time In this case use Edge interrupt The following program is an example of using Edge interrupt 138 COMFILE Technology PICBASIC DATABOOK Sender s program with Flow control CONST TX PIN 0 CONST FLOW 16 CONST BAUD 103 DIM AS BYTE ON INT 16 0 GOSUB 10 OUT TX PIN 1 Set sending pin HIGH at first part of a program 100 100 Executes main program endless loop 10 DELAY 1 Set some delay to let a receiver prepare SEROUT TX PIN BAUD 0 1 PICBASIC RETURN Receiver s program with Flow control CONST RX PIN 0 CONST FLOW 16 CONST BAUD 103 DIM AS BYTE DIM A 10 AS BYTE SET PICBUS HIGH OUT FLOW 1 Set Flow pin HIGH 10 DELAY 1000 Execute other works DELAY 1000 OUT FLOW 0 Send a sender a signal indicating that a receiver is ready to Receive data Set Flow pin LOW SERIN RX_PIN BAUD 0 5000 10 A 0 8 OUT FLOW 1 Set Flow pin HIGH after receiving data FORI 0TO7 LOCATE 1 0 PRINT NEXT I GOTO 10 The following picture shows the result of measurement with an oscilloscope for above example communication As you can see in the picture sending data starts after Flow drops to LOW state With this Edge interrupt method timing problem of communication can be resolved for both of sender and receiver TekStop 1 Data Flow 2 00V MQ 00ms Ch X 2 60V COMFIL
38. 0 Read value being outputted to portO ADDITIONAL INFORMATION The instructions related to port are as follows IN make corresponding port input and read the state of pin outside OUT make corresponding port output and change pin state OUTSTAT make corresponding port output and read content of internal output buffer COMFILE Technology 99 PICBASIC DATABOOK PADIN PADIN port block Keypad input Port block is a constant 0 3 or a Byte variable indicating port block number EXPLANATION This instruction reads 4X4 key matrix from specific port block It is convenient to read input of dial keypad If there is a key input it returns 0 Otherwise it retums scan code of the key The circuit of key pad must be organized as the following picture Lower 4bits are for output and higher 4bits are for input Higher 4bits must be pulled up 5K 10K 015 1014 SCAN CODE 1 013 012 rom 16 12 8 4 1 010 15 11 7 3 14 10 6 2 i 13 9 5 1 08 In case of PBM R1 R5 you can use PADIN instruction at port block 1 2 and 3 EXAMPLE PADIN 1 Read keypad from port block 1 100 COMFILE Technology PICBASIC DATABOOK PEEK PEEK file register Read file register File register is a file register number 0 amp HFF Not available with variable EXPLANATION This instruction reads a file register of main MCU directly You can see various file registers in the file register map Refer to data book
39. 016 mew _ j T a ms nes j T j eo om 91 j s oma rona Tr s owas Fe Tr 79 oss ets Tr s won rmn s x Fee wer s 4 v won rms me s mox cwm 1 a Fee so s z wow s m Fe se s 1 woe Fe se s Fem se s von Fez mex sr 18 COMFILE Technology PICBASIC DATABOOK z wm wm w sr s won Fem se s s won Fem ses s 3 Fem ses s s vos Fem ses st o en es s Fem ses s a Fem ses s 3 Fem es s Fem s ar ADinputonty 3s Ponas caus tm ves Realtime cock All pins except Vpp Vss and RESET is used for I O ports are arranged in order of their number and are blocked by eight ports The blocked eight ports
40. 04 AD4 7 g O17 5 GND 8 O16 t OSCIN 9 5V OSCOUT 1 UJ 22pF 1 08 1 09 PWM0 014 1 010 PWM1 013 1 011 012 PICBASIC PROGRAMMING First you need to connect a PICBASIC module to PC with the PICBASIC cable After connection you can program with PICBASIC studio on PC The PICBASIC studio is Integrated Development Environment for PICBASIC and is released free of charge by Comfile Technology You can download it at www comfile co kr The program takes course of compiling and downloading and running by clicking RUN button in PICBASIC studio When occurring errors in process of compiling a error message will appear PICBASIC studio 3lines Download cable wa ZR Printer port PICBASIC IBM PC Downloading program through dedicated cable Rev B cable User target board PROGRAM MAINTENANCE When you need to revise modify a program you just simply re connect the PICBASIC cable to PC and revise modify the program on PICBASIC studio The program is stored at EEPROM which keeps its data even at power off state COMFILE Technology 7 PICBASIC DATABOOK PICBASIC CABLE Download cable for PB series uses three lines to connect with printer port Download cable for PBM series named Rev B cable includes a microprocessor performing error detection and speed control between PC and PICBASIC It insures to prevent various problems in downloading PRINTER PORT PRINTER PORT to in to PICBASIC 12
41. 1 15 25 2 Parameter Frequency Parameter Frequency 1 258Hz 1 1 227KHz 10 267 5Hz 10 1 274KHz 20 278 7Hz 20 1 324KHz 40 304 7Hz 40 1 439KHz 80 374Hz 80 1 77KHz 100 421 8Hz 100 2KHz 191 1KHz 153 3KHz 200 1 17KHz 200 5 58KHz 230 2 5KHz 230 12KHz 253 21 9KHz 253 104KHz You could find out that the higher the frequency band is the wider variation width of frequency per parameter is Maximum parameter is 253 and when parameter is 254 or 255 there isn t frequency output CAUTION FREQOUT instruction cannot drive port 9 and port 10 simultaneously FREQOUT instruction can use one of those two ports While you use FREQOUT instruction you cannot PWM instruction Contrary while you use PWM instruction you cannot FREQOUT instruction COMFILE Technology 75 PICBASIC DATABOOK FLOAT String variable FLOAT value position position2 Converting Single type into Sting type Value is a Single constant variable Position1 is the maximum positional number for integral part It is possible up to 10 and default value is 9 N A with variable Position2 is the maximum positional number for fractional part It is possible up to 10 and default value is 6 N A with variable EXPLANATION This instruction converts Single constants variables into Single string EXAMPLE The following table shows the results of each instruction in accordance with variation of parameter SN is 1234 56789 and b is
42. 1 INS CAPS NUM If you encounter the error message PICBASIC Module Not Found Check Cable or Power during download process you should look into hardware component and their connection such as cable electric power and etc Electric power must be supplied from Target board After checking all components and their connection if you figure out nothing wrong You should adjust address of Printer port You can find the Printer Port set box in Setup menu in the Tool bar You can select one of 378 278 and 3BC as address of the printer port Printer Port setup Printer Port Address Most of PC works UP TI 378H with this address If you use PB series in MS Windows 2000 NT XP you must check this box Iv Use Interigent Gablethey when PB serise Cancel COMFILE Technology 31 PICBASIC DATABOOK FILE MENU New Ctrl N Open Save F2 Save Save Object Download from Object Print Printer Setup bas documentsttestd bas DittMy documentstftest3 bas documentsttest2 bas Exit New make new file Open open existing file Save save current working file Save As save current working file in different name Save Object save only Object code from current working file Download from Object download only Object code SAVE DOWNLOAD OF OBJECT CODE Generally you can save keep your source fil
43. 15432 10 R5 777 SETRS222 777 777 77 77 7777 27 3 PEEL 227 977 77 7 77 7 277 BLEN BLEN 777 SET RS232 9600 RS232C DIM I AS BYTE DIM A 12 AS BYTE ON RECV GOSUB 100 299 FUR 4007777 77 10 GOTO 10 7 T3 100 IF BLEN 0 lt 12 THEN RETURN 12 77 11 27 27 poc 0 293 LOCATE 1 1 PRINT CHR A l LCD p NEXT I RETURN 7777 7777777 e 7777 777 77177 777 777 146 COMFILE Technology PICBASIC DATABOOK 2 2 1 1 DELAY 7777 27271 77 TT POLL 2 1077 77777 2777 7 7 7 2777777 77 7 777 1 7 2 SERN 1 SERN 2 SERIN 2 l 77 1 SERN 277 22 2 777 77 VO e DIM I AS BYTE DIM A 12 AS BYTE 10 SERIN 15 93 0 5000 10 A 0 12 11 1 0 PRINT CHR A l NEXT I GOTO 10 SERIN 4 24 2 e 1277777 1 SERIN SERN 77 1 1 SERIN Pe 1
44. 232C is fixed as 8bit 1 stop bit No Parity Each PICBASIC modules has unique transmission speed in according to baud rate as show below table These rates are same in SEROUT instruction Transmission speed Transmission speed Transmission speed 1 15 25 2 1 5 EXAMPLE SERIN 2 196 0 5000 TIMEOUT I Receive data from port 2 at 4800 baud rate Jump to TIMEOUT routine if there is no data Input in five seconds 112 COMFILE Technology PICBASIC DATABOOK ADDITIONAL INFORMATION Receiving control statement 1 WAIT You can make Multi drop communication which is a method assigning a kind of address to each receiving device by WAIT This is frequently used in RS485 433 communication SERIN instruction waits for appointed characters 2bytes by WAIT and stores data following the appointed characters close behind into an appointed variable SERIN 2 66 0 50000 TIMEOUT WAIT AB I Receive data from port2 at 4800 baud rate Wait for receiving character A B After receiving character B store data following behind into and finish a program Receiving control statement 2 until When array are used to receive several bytes simultaneously if a specific character is received receiving process is stop SERIN 2 66 0 50000 TIMEOUT UNTIL A 0 10 During receiving 10 bytes to array A if is received stop receiving Receiving control statement 3 skip When
45. 2bit floating point number with sign String 8bit character extended up to 92 byte at most Byte variable is a type of 8bit number without sign and reserves 8bits 1byte of memory space Therefore its expression range is 0 225 Integer variable is a type of 16bit number without sign and reserves 16bits 2bytes of memory space So its expression range is 0 65535 Long variable is a type of 32bit number with sign and reserves 32bits 4bytes of memory space So its expression range is 2 147 483 648 2 147 483 647 Single variable is a type of 32bit of floating point number with sign In accordance with recommendation of IEEE 754 it consists of seven bits of exponential part twenty three bits of point part and one sign bit MSB LSB 31 30 29 2322211201918 17 16 15 14 13 12 111019817 615 413 2110 28272625124 RM Sign Exponential Integer String variable is available in PBM series only It can be 93byte at most and must be used with value indicating its maximum bytes for reserving memory space Refer to the following example DIM ST AS STRING 14 Declare ST as string variable with 14byte of maximum bytes The following picture describes how string data is stored in memory when maximum bytes of string variable is 14 bytes If the maximum byte is 14 2byte of additional memory is reserved One byte is for the value indicating
46. 3 0 234 192 14 90 100 20 1 2 0 1 0 0 0 In addition it is inhibited to use operating expression the middle of command IF 2 0 THEN K 0 Improper usage of operation 2 IF 0 0 44 COMFILE Technology PICBASIC DATABOOK Floating point operation in PB series To use floating point number in PB series you need some trick For instance when you multiply 200 by 3 14 you cannot the operation in PB series In this case if you use Scaling method you can obtain same or approximated result as that of Floating point operation Refer to the following sample program 200 3 14 Desired result is 628 SET PICBUS HIGH LCDINIT DIM AS INTEGER 200 1 200 3 1 200 1 10 1 1 200 4 100 1 0 0 PRINT DEC I 10 GOTO 10 LCD displays 628 When you want to convert a value 0 255 of a A D port into other value 0 1000 1000 256 3 90625 You multiply the value of A D port by 3 90625 The program for this is as follows SET PICBUS HIGH LCDINIT DIM I AS INTEGER DIM J AS INTEGER 10 1 0 1 3 J 1 9 104J LOCATE 0 0 PRINT DEC I LOCATE 0 1 PRINT DEC J GOTO 10 Value of A D is on the upper line Result of conversion is on the lower line Because only 3 9 is used for above multiplying there is some error in the result of conversion Though the maximum value is 994 it is still useful trick in
47. 3 PICBASIC MODULES PICBASIC modules are classified as three types of series PB 1X 2X series The first PICBASIC series PB 1B PB 1S PB 2S PB 2H PB 3X series One chip controller series Faster speed and economic price PBM RX series Dual processing controller series Floating point math Hardware RS232C String PBM R1 PBM R5 PB 3B PB 3H PB series in this document is means modules of which name stars with PB such as PB 1B PB 1s PB 2S PB 2H PB 3B PB 3H while PBM series means PBM R1 and PBM R5 COMFILE Technology PICBASIC DATABOOK SPECIFICATION PB 2H PB 3B PB 3H PBM R1 PBM R5 Main Memory 2Kbyte 4Kbyte 8Kbyte 16Kbyte 4Kbyte 4Kbyte 32Kbyte 64K byte Data Memory 96byt 96byte 96byt 96byte 80byte 80bye 8Kbyte 32Kbyte ports 16 16 27 27 21 29 34 34 Main processor PIC16C73 PIC16C73 PIC16C74 PIC16C74 PIC16F876 PIC16F877 PIC16F877 PIC16F877 4 19MHz 4 19MHz 419MHz 20MHz 20MHz 20MHz 20MHz 20MHz requency Execution rate 43 4times 13 9 13 9 mes 3 1 mes times 1times 1 4 14times comparison Memory Access serial serial serial serial serial serial serial Serial EEPROM 8Kbyte 32Kbyte No of Pin 21 21 34 34 28 40 40 40 A D channel 5 5 8 8 5 8 8 8 Resolution 8 bit 8 bit 8 bit 8 bit 106 10bi 1059 10bit 12
48. ABOOK TIMESET TIMESET address data Change real time data Address is a constant 0 6 or a Byte variable Data is a constant 0 255 or a Byte variable EXPLANATION This instruction revises data of real time clock DS1302 in PBM R5 module Factory default is dummy value So oan 1_ 0469 4 Mmh 1 812 1 8 7 m RET Die teni 6 Yw ose EXAMPLE Must be hexadecimal type for storing in the forms of BCD TIMESET 1 amp H30 Set current minute 30 TIMESET 2 amp H2 Set current hour 2 TIMESET 3 amp H10 Set current date 10 TIMESET 4 amp H1 Set current month January COMFILE Technology 129 PICBASIC DATABOOK The following table shows the relation between BCD code hexadecimal and decimal Because that TIM and TIMESET instructions use BCD code it is much easier to store display by hexadecimal Time BCD code Hexadecimal Decimal IN O A N IN O A Jw N o N N 8 N o N NX 130 COMFILE Technology PICBASIC DATABOOK VAL PETI Integer variable VAL string Convert string into Integer value String is a Sting variable EXPLAN
49. ATION This instruction converts string into Integer value When a string expresses Integer value such as 12345 it convert into figures 12345 When a string is not value such as KOREA it converts into 0 The result of this instruction must be stored at Integer variable EXAMPLE DIM ST AS STRING 16 Set maximum length of string 16 DIM AS INTEGER ST 12345 VAL ST 12345 is stored at l VALSNG PETI Single variable VALSNG string Convert string into Single value String is a String variable EXPLANATION This instruction converts string into Single value When a string expresses Sing value such as 12345 5678 it convert into figures 12345 678 When a string is not value such as KOREA it converts into 0 The result of this instruction must be stored at Single variable EXAMPLE DIM ST AS STRING 16 Set maximum length of string 16 DIM C AS SINGLE ST 12345 5678 VALSNG ST 12345 5678 is stored at ST COMFILE Technology 131 PICBASIC DATABOOK PB to PBM conversion in program Although most of programs which are programmed by PB series PB 1B PB 1S PB 2S PB 2H PB 3B and PB 3H can be executed by PBM series because that some of instructions for PB series are changed or excluded you need to modify a program programmed by PB series to use PBM series Refer to the following description carefully for converting a program INSTRUCTION OF PB SERIES Instruction Co
50. BOOK KEYIN Integer variable KEYIN port chattering delay Key input Port is a constant 0 31 or a Byte variable Chattering delay is time by mS and a constant 0 255 Default value is 20mS EXPLANATION This instruction reads the state of specific port HIGH or LOW after eliminating chattering The instruction is used mainly to Switch input The chattering delay is specified by mS For instance KEYIN 0 100 reads the HIGH LOW state of port 0 after 100mS of chattering delay If you omit the chattering delay it becomes default value 2015 EXAMPLE DIM AS BYTE Declare byte type KEYIN 0 100 Read key input state of port 0 after 100mS of delay 0 Read key input state of port 0 after 20mS of delay ADDITIONAL INFORMATION The following picture 1 is general key input circuit It turns LOW state when switch is pushed 5V 10K y os Picture 1 Key input circuit Picture 2 Chattering Mechanical switching components generate chattering which is vibration of voltage during switching process as picture 2 It usually comes out around 10mS If you don t eliminate Chattering at S W input there may occur errors such as double operation by one input Therefore you must perform elimination of Chattering in S W input circuit PICBASIC resolves this by software l e in case of KEYIN 0 100 it recognizes a signal as input when it receives same signal during 100mS COMFILE Technol
51. CBASIC DATABOOK Step 4 In a moment you will see the message box asking if you open save the pbstv10 zip or not Click Open button Then installation will be proceeding x 2 Some files cen your conpule the He information below looks or you do not fully mas Ihe eceace do open 01 save this fie File pbstu10 2p File pe Compressed zpped Folder Free pwan comt Would you fke to open the He ce it ta peur computer eat More V Alasys ork before opereng thre oF file Step 5 While Setup is proceeding you can set installation option such as destination folder program folder etc Please keep your eyes on screen and follow the message appearing at each stage of installation GETTING LATEST VERSION OF PICBASIC STUDIO We Comfile Technology upgrade our software almost every month irregularly Therefore to get latest version of PICBASIC studio we recommend you to visit our web site for software upgrade regularly at least every month The download page for international users is www comfile co kr english download html SPECIAL NOTICE FOR USING REV B CABLE ON PICBASIC STUDIO Rev B cable is a intelligent cable containing a microprocessor and is dedicated for PICBASIC modules PB series and PBM series If you are using MS Windows XP you should allocate the LPT1 to HP Laser jet 4 Because that the driver of HP Laser jet4 is in MS Window XP driver
52. E Technology PICBASIC DATABOOK When there is no current consumer at output part you can get output of D A conversion easily by organizing the following circuit 22K PICBASIC 2000 e Analog Output PORT lt AT When there is a current consumer at output part Voltage variation would be occurred Therefore you should build a buffer by using OP amp Input Output Noninverting amplifier circuit Inverting amplifier circuit COMFILE Technology 67 PICBASIC DATABOOK DELAY DELAY mS Delay by mS mS is a Byte Integer constant variable specifying the length of delay in milliseconds EXPLANATION This instruction generates delay for specified time in mS The range of delay is 0 65535 EXAMPLE DELAY 2000 Delay 2000mS 68 COMFILE Technology PICBASIC DATABOOK DEC DEC value position parameter Convert into Decimal string Value is a Byte Integer Long constant variable Position is the maximum length of position Up to 10 Default is 5 Constant only Parameter is a constant 0 or 1 only indicating to display 0 in front of a converted string or not O shown 1 not shown Default is 1 EXPLANATION This instruction converts constants variables into decimal string PB series can use this instruction only for in PRINT instruction PBM series can store the result of DEC instruction in a String variable EXAMPLE The following table shows
53. E Technology 139 PICBASIC DATABOOK 140 COMFILE Technology PICBASIC DATABOOK Communication with PC To communicate PBM R5 with PC through RS232C connect PBM R5 to PC through PICBASIC PnP board as following picture Connect port 15 to RX and port 14 to TX with 1 1 cable Connecting to RS232C port of PC with one to one cable X PICBUS olo IN PE PN P31 P30 9 Copyright 2000 COMFILE Technology P27 P26 25 24 P23 P22 P21 P20 P19 P18 P17 P16 P15 P14 P13 P12 Single Board Computer PICBASIC 2000 Flash 64K RAM 32K EEPROM 32K 12bit ADC RTC 34 I O COMFILE ud s p 9 5 9 Q Q Q P1 o o o o o o o o sen O m a o o O
54. K SET ONINT SET ONINT ON OFF on off edge interrupt EXPLANATION This instruction activates inactivates edge interrupt of port 8 The initial state of ON INT 0 GOSUB instruction is ON If you use the instruction without declaration of ON INT you will encounter error EXAMPLE SET ONINT ON Activate Edge interrupt SET ONINT OFF Inactivate Edge interrupt SET ONRECV SET ONRECV Tum on off RS232C receiving interrupt EXPLANATION This instruction activates inactivates RS232 receiving interrupt of port 8 The initial state of ON RECV GOSUB instruction is ON If you use the instruction without declaration of ON RECV you will encounter error EXAMPLE SET ONRECV ON Activate RS232 receiving interrupt SET ONRECV OFF Inactivate RS232 receiving interrupt COMFILE Technology 117 PICBASIC DATABOOK SETONTIMER SET ONTIMER ON OFF Turn on off timer interrupt EXPLANATION This instruction activates inactivates timer interrupt of port 8 The initial state of ON TIMER 0 GOSUB instruction is ON If you use the instruction without declaration of ON TIMER you will encounter error EXAMPLE SET ONTIMER ON Activate timer interrupt SET ONTIMER OFF Inactivate timer interrupt USAGE OF INTERRUPTS IN PB SERIES All interrupts in PB series is activated constantly If you want to stop an interrupt temporarily you should check a corresponding flag and return instantly at first part of an interrupt routine
55. M 9 1 Output PWM waveform by duty rate to port 9 GOTO 10 108 COMFILE Technology PICBASIC DATABOOK PWMOFF PWMOFF port Stop outputting PWM wave Port a constant 9 or 10 or a Byte variable EXPLANATION Once PWM instruction is executed the corresponding port keeps outputting PWM To stop the output you should use PWMOFF instruction Ports for PWM output port9 and port10 are in PWMOFF state at power on reset EXAMPLE PWMOFF 9 Stop outputting PWM at port9 PWMOFF 10 Stop outputting PWM at port10 COMFILE Technology 109 PICBASIC DATABOOK RESET RESET Initialize main processor EXPLANATION This instruction initializes a processor by software It takes effect as electric power reset EXAMPLE RESET Reset processor RIGHT Sting variable RIGHT string value Cut right part of string String is a String variable Value is a Byte constant variable EXPLANATION This instruction cuts part of string constant variable as much appointed from the right EXAMPLE DIM ST AS STRING 16 Set maximum length of string 16 DIM RE AS STRING 16 ST I LOVE YOU RE RIGHT ST 3 LOCATE 0 0 PRINT RE YOU is displayed on LCD 110 COMFILE Technology PICBASIC DATABOOK RND 0 RND 0 Random number EXPLANATION This instruction generates random number 16bits integer 0 in the brackets is meaningless dummy value EXAMPLE RND 0 Store random number into variable I PRINT DEC I
56. N GOTO 100 When F1 SINGLE and I1 INTEGER CAUTION 3 Comparison between string variables is not available DIM ST1 AS STRING 12 DIM ST2 AS STRING 12 IF ST1 ST2 THEN GOTO 100 COMFILE Technology 83 PICBASIC DATABOOK IN Integer variable IN port Port input Port is a constant 0 31 or a Byte variable EXPLANATION This instruction read the state HIGH or LOW of specific port When it is HIGH the instruction returns 1 When LOW it returns 0 EXAMPLE DIM AS BYTE Declare byte type IN 0 Read the state of port 0 ADDITIONAL INFORMATION All port of PICBASIC modules is bidirectional As INPUT OUTPUT direction of the ports is can be set freely by instruction ports shall be INPUT port on INPUT instruction and be OUTPUT port on OUTPUT instruction automatically When a port is INPUT port it is at high impedance floating state In case of other programming language such as C and Assembly I O instruction must be used with declaring I O direction of ports In case of ports of TTL input ports is recognized as HIGH when input voltage is higher than 1 4V and as LOW when input voltage is lower than 1 3V In case of ports of Schmitt trigger input ports is recognized as HIGH when input voltage is higher than 3 4V and as LOW when input voltage is lower that 3 3V REFERENCE All ports become HIGH state high impedance at initial state when electric power turns on 84 COMFILE Technology PICBASIC DATA
57. PB series COMFILE Technology PICBASIC DATABOOK Instructions PBM series only PB series only Declaration instructions DIM CONST CONST BYTE CONST INTEGER CONST LONG CONST SINGLE Declare variable and array Declare constant Declare Byte constant array Declare Integer constant array Declare Long 32bit constant array Declare Single constant array Flow control instructions Digital instructions IF THEN FOR NEXT GOTO GOSUB RETURN BYTEIN OUT BYTEOUT OUTSTAT TOGGLE PULSE RS232C instructions m SERIN SEROUT GET PUT SET RS232C BLCR BLEN Shift instructions SHIFTIN SHIFTOUT Evaluate a condition and if it is true go to appointed line Repeat execution of instructions Branch to specific line Call a subroutine and return Read status of port Read eight ports simultaneously Set status of port HIGH or LOW Change eight ports simultaneously Read value being outputted from a port Reverse current value being outputted Reverse output state during specific period Pulse output Software instruction for receiving RS232C Software instruction for transmitting RS232C Hardware instruction for receiving RS232C Input port is 14 Hardware instruction for transmitting RS232C Output is 15 Hardware instruction for initializing RS232C Initialize receiving buffer of RS232C Return number of data received at receivin
58. PICBASIC DATABOOK VOL 10 COMFILE Technology Inc 30 1 Shingae dong Yongsang ku Seoul 140 190 Korea Tel 82 2 711 2592 Fax 82 2 711 2593 E mail Comfile comfile co kr Internet www comfile co kr PICBASIC DATABOOK UPGRADE INFORMATION All resources related to PICBASIC such as firmware IDE and manual etc may be upgraded irregularly for improvement without notice The information about that is released at COMFILE Technology web site www comfile co kr and its details are as follows IDE IDE integrated Development Environment for PICBASIC PICBASIC studio and PICBASIC LAB are able to be downloaded at www comfil co kr free of charge PICBASIC FIRMWARE Upgrade information for firmware inside of PICBASIC module will be announced at COMFILE Technology web site www comfile co kr Upgrading firmware of PB 3X and PBM RX is free of charge while that of PB 1X and PB 2X cost TRADEMARK Microsoft Internet Explorer Windows Windows NT Windows 2000 and Windows XP are registered trademarks of Microsoft Corporation in the United States and or other countries The Microchip logo and name PIC and PlCmicro are registered trademarks of Microchip Technology Incorporated in the U S A and other countries PICBASIC is registered trademark of Comfile Technology Inc in Republic of Korea and other countries NOTICE Information contained in this data book may be changed without notice and be intended by way of suggestion S
59. S LONG DIM JASBYTE 255 1 1 Result become 0 because variable J is Byte type The following table shows operators available in PICBASIC Arithmetical operation Logical operation and shift Available in all variable types Available in Integer variable only Addition AND Logical operation AND Subtraction OR Logical operation OR Multiplication XOR Logical operation XOR Division lt lt Left shift gt gt Right shift MOD remainder of division Operation priority is order of multiplication division bit operation addition and subtraction l J 12 K Multiply 12 by and add J 1 AND amp HF AND operation with and amp HF and add COMFILE Technology 43 PICBASIC DATABOOK Complicated operation has possibility of occurring errors during compiling In that case it is recommended to divide the operation into several simple operations I J K L 4 l J K l 1 L 4 In case that an operation makes no temporary data in performing operation it does not matter how long the expression is l J K L 4 100 CAUTION PICBASIC does not allow using a function inside of other function PRINT DEC ASC ST This instruction must be modified as below ASC ST PRINT DEC I In case of PBM series you can divide a line of expression into more than one line by using _ This is not available in PB series TABLE J 192 12 13 142 12
60. TION This instruction retums SIN value of value Angle by radian Value must be Single type If value is not Single type you must convert it into Single type by CSNG instruction EXAMPLE DIM F1 AS SINGLE F1 SIN 1 0 Angle should be expressed by radian Radian Angle 3 14 180 SOUND SOUND port interval length Generate sound Port is a constant or a Byte variable specifying port number Interval is a Byte constant variable Length is a Byte constant variable EXPLANATION This instruction generates simple sound To use this instruction you should connect PIEZO etc to specific port Interval is pitch of sound such as do re mi fa and sol Each sound has unique frequency and SOUND instruction generates the frequency to make sound Approximately when 233 139 are inputted you can get sound of do re mi fa sol la and this in one octave The larger Length is the longer sound last When Length is 16 sound lasts around Quarter note PBM series can use port 0 15 as output of SOUND EXAMPLE SOUND 5 239 10 Generate sound of 239 interval and 10 length at 5 SOUND 5 239 10 159 10 you can use intervals and lengths in a row COMFILE Technology 123 PICBASIC DATABOOK SQR Single variable SQR value Square root Value is a Single constant variable EXPLANATION This instruction returns a square root of value Value must be single type If value is not Single type you must
61. alue to appointed port block which consists of eight ports All ports in the port block assigned by BYTEOUT instruction become output state EXAMPLE PB 1B 1S Q OQ cO sx tO r 00 O 9822389255882 5558552 85885 55 85 BLOCKO BLOCK 1 amp HAB 0 1 Output content of to port block 0 COMFILE Technology 59 PICBASIC DATABOOK CAPTURE Integer variable CAPTURE port target Capture pulse Portis a capture port and is a constant 0 3 or a Byte variable Target is a constant 0 or 1 only and is not available with variable EXPLANATION This instruction measures interval of incoming pulse HIGH or LOW from a capture port When a capture target is 0 LOW interval is measured When the capture target is 1 HIGH interval is measured EXAMPLE CAPTURE 0 0 Measure interval of LOW pulse at port 0 Start point of instruction Start point of capture End point of capture 1500 5 Right after executing of the instruction the interval of the first incoming LOW pulse is captured and divided by a certain value see following table and retumed CAPTURE instruction starts at Start point of instruction and wait for detecting end point of instruction If the end point of capture is out of maximum capturing range it will return 0 not waiting for the end point of instruction 1 15 25
62. and sending DEBUG information to PCP Because this instruction is deducted for debug mode it can not operate at state that a PICBASIC module is not connected with PC Execution of this instruction changes PICBASIC studio window to DEBUG mode window displaying the location where execution stop and contents of each variables and so on Refer to description of DEBUGGING in end of this chapter CAUTION If you insert BREAK instruction into an endless loop it makes endless break causing logical error in operation Therefore you should use BREAK instruction in where the BREAK instruction executes once or by key input In order to escape from endless loop executing BREAK instruction you should use ERASE ALL button and get out of the loop 56 COMFILE Technology PICBASIC DATABOOK BUSOUT BUSOUT value value Transmit specific code to PICBUS Value is a constant 0 255 or a Byte variable EXPLANATION This instruction transmits numbers to PICBUS pin PICBUS pin is dedicated port connecting with LCD display module When you want to display specific code on LCD use this instruction EXAMPLE 10 BUSOUT amp amp H01 Transmit A0 1 A3 to PICBUS GOTO 10 COMFILE Technology 57 PICBASIC DATABOOK BYTEIN Integer variable BYTEIN port block Input by byte Port block is a port block number 0 3 or a Byte variable EXPLANATION This instruction reads eight ports simultaneously and save them at a
63. ariable EXPLANATION This instruction outputs data through RS232C hardware The data is outputted through I O port 14 in the format of 8bit none parity and 1 stop bit Before using this instruction you must execute SET RS232 instruction Data must be Byte type If you use Integer or Long type data only lower 8bits will be transmitted Single data cant be transmitted If you use String variable as data all content of String variable will be transmitted EXAMPLE SET RS232 4800 DIMIAS BYTE amp Ha0 PUT Send content of variable Carriage return character wont be sent SET RS232 4800 DIM ST AS STRING 30 ST LOVE PICBASIC 2000 PUT ST Send content of String ST Carriage return character wont be sent CARRIAGE RETURN CHARACTER Other Basic languages such as QBASIC etc transmit carriage retum character 13 and 10 automatically Those character are kind of command code moving to the first part of next line However PBM series cannot use the carriage return character COMFILE Technology 107 PICBASIC DATABOOK PWM PWM port duty rate cycle PWM port duty rate Generate PWM wave Port is a constant 9 or 10 or a Byte variable Duty rate is a Byte constant variable In case of PBM series Integer constant variable because of 10bits Cycle is a Byte constant variable EXPLANATION This instruction outputs PWM to specific port Duty rate is adjustable in the range between 0 and 1023 The larger the
64. array are used to receive several bytes simultaneously if a specific character is received the specific character is skipped SERIN 2 66 0 50000 TIMEOUT SKIP R A 0 10 During receiving 10 bytes to array A character R will be skipped When you use WAIT UNTIL and SKIP all together you must use them in order of WAIT UNTIL and SKIP PBM series cannot use UNTIL and SKIP Incase of receiving several bytes You can use an array or a string variable for a receiving variable When you use an array you can receive several bytes on simultaneously by using It is used when data is sent continuously SERIN 2 93 0 50000 TIMEOUT I 0 5 When an array is used for a receiving variable you can appoint number of receiving byte Receive 5bytes from 0 i e receive bytes 1 0 1 2 3 4 SERIN 2 93 0 50000 TIMEOUT ST 5 Receive 5bytes to string variable ST at this moment the last byte of data must be 0 because that 0 means end of string Make certain not to exceed maximum range of string declared by DIM at first part of a program RS232C receiving interrupt in PB series RS232C receiving interrupt stops executing instructions of a program other than SERIN when RS232C data transmission is detected and executes receiving RS232C In order to make this edge interrupt is used ON INT 5 0 GOSUB RS232_INT main program RS232_INT SERIN 5 11 0 1000 TIMEOUT BF
65. ated PICBASIC assign port14 and port15 as RS232C ports and initialize them You can use one of baud rates shown in following table SET RS232 2400 2400 baud rate SET RS232 4800 4800 baud rate SET RS232 9600 9600 baud rate SET RS232 19200 19200 baud rate SET RS232 38400 38400 baud rate SET RS232 57600 57600 baud rate SET RS232 76800 76800 baud rate SET RS232 96000 96000 baud rate SET RS232 115200 115200 baud rate EXAMPLE The following program displays data from PC on LCD and ECHO SET RS232 4800 Declare hardware RS232 at 4800 baud rate DIM DATA AS BYTE LCDINIT CSROFF 10 GET DATA 100 IF DATA 0 THEN GOTO 10 PRINT CHR DATA Display received data on LCD PUT DATA DATA 0 GOTO 10 120 COMFILE Technology PICBASIC DATABOOK SHIFTIN SHIFTIN CLK port DATA port mode bit Ports interrupt CLK port is a constant or a Byte variable specifying port number generating clock OUTPUT DATA port is a constant or a Byte variable specifying port number reading data INPUT Mode 0 Starting with LSB Least Significant Bit Sampling after CLK rising 1 Starting with MSB Most Significant Bit Sampling after CLK rising 2 Starting with LSB Least Significant Bit Sampling after CLK falling 3 Starting with MSB Most Significant Bit Sampling after CLK falling Bitis a constant specifying bit number up to 16 Default is 8 EXPLANATION This instruction receives Shift Input It is mainly used to
66. ble reaches end value Variable1 is increased or decreased by increment For instance FOR 150 TO 50 will executes commands instructions between FOR and NEXT 51 times It starts on 1 and finishes on 1550 variable2 can be omitted Increment is not available in PB series In PBM series you can adjust increment or decrement of variable by STEP instruction STEP instruction can use 128 127 as increment value EXAMPLE FOR 0 TO 50 BYTEOUT 1 1 Repeat with increment of from 0 to 50 NEXT I FOR 0 TO 50 FOR J 0 TO 100 PRINT DEC J Repeat 101 51 times NEXT J NEXT I The following example is available in only PBM series FOR 0 TO 50 STEP 3 BYTEOUT 1 1 Repeat with increment of by 3 from 0 to 50 NEXT I 50 TO 0 STEP 1 BYTEOUT 1 1 Repeat with decrement of by 1 from 50 to 0 NEXT I COMFILE Technology TT PICBASIC DATABOOK GET GET variable delay jump label Receive RS232C data by hardware Variable is a Byte String variable receiving data from RS232C buffer Delay is an Integer constant variable specifying wait time for data when no data in RS232C buffer Jump label is where to jump to in case that there is no incoming data after delay EXPLANATION This instruction receives data through hardware RS232C and is available with only PBM series SET RS232 instruction must precede GET instruction that reads received data at RX terminal I O port 15 Hardware RS232 is full duplex bufferin
67. ceiving interrupt such as ON RECV etc To work with RS232C communication you should need understand of RS232C communication standard usage of corresponding instructions and how to handle a counterpart device First would like to describe two methods to control RS232C by PICBASIC One is SERIN and SEROUT instructions which control RS232C on software These instructions do not use hardware circuit of RS232C inside of a microchip to control RS232C communication They use normal I O port to execute RS232C communication On the other hand PBM series have GET and PUT instructions Because that these instructions use hardware RS232C circuit built in microchip they are able to provide with lots of functions that SERIN and SEROUT instructions can not provide with However SERIN and SEROUT instruction also have some functions that GET and PUT instructions cannot provide with Therefore you should completely understand the differences between those two methods and select a proper method or combine them in accordance with desired purpose The following table shows the differences between above two methods Instruction SERIN SEROUT GEI PUT BCLR ON RECV BLEN Principle Controlling RS232C communication by software of interpreter Using built in hardware RS232C communication port Port Free to select port PBM series can use ports from 0 to 15 RX port15 TX port14 Baud rate PBM series 300 19200 PB series 2400
68. convert it into Single type by CSNG instruction EXAMPLE DIM F1 AS SINGLE F1 SQR 4 0 2 0 is stored at F1 124 COMFILE Technology PICBASIC DATABOOK STEPOUT STEPOUT port interval number of times stop port stop level Output pulse for controlling stepping motor Port is a constant 0 31 or a Byte variable specifying port number Interval is a constant 1 255 or a Byte variable specifying pulse interval Number of times is a constant 1 65535 or a Integer variable Stop port is a constant 0 31 specifying port number for stop input Stop level is a constant 0 or 1 EXPLANATION This instruction output wave specific number of times every interval By supplying the wave to a stepping motor drive you can drive a stepping motor simply Generally a stepping motor used for positioning needs extra drive for connecting a controller By providing the controller with pulse the stepping motor will rotate as much as provided pulse If a stepping motor rotates 1 8 per one pulse providing 10 of pulse makes the stepping motor rotate by 18 PICBASIC Stepping motor C cow PB 1B PIC16C73 04SP 2834 p PIG Motor controller EXAMPLE STEPOUT 2 50 10 Output wave ten times every 50 interval to port2 motor rotates by 18 STEPOUT 2 20 10 Output wave ten times ev
69. cursor EXPLANATION This instruction turns on a LCD cursor CSROFF CSROFF Turn off LCD cursor EXPLANATION This instruction turns off a LCD cursor CLS CLS Clear LCD screen EXPLANATION This instruction clears LCD screen COMFILE Technology 65 PICBASIC DATABOOK DACOUNT DACOUT port duty rate output D A conversion output Port is a constant 0 31 or a Byte variable PBM series is 0 15 Duty rate is a constant 0 255 or a Byte variable Output is output number of waveform and is a constant 0 65525 or a Byte Integer variable EXPLANATION For D A conversion this instruction outputs PWM wave form to a specific port for appointed time and make the port high impedance state HIGH Z To use the instruction you need an extra circuit consisting of registers condensers and OP amps The instruction is similar as PWM instruction in operation However DACOUT instruction is free to select ports while PWM instruction is restricted from selecting ports The following table shows the differences between DACOUT and PWM DACOUT PWM PORT in case of PBM series 0 15 9 10 Output method software hardware Frequency Fixed 2 4KHz variable Continuity of output N A Keep outputting till PWMOFF EXAMPLE DACOUT 5 100 120 41245 lt gt Stil 120 5 10 200 41208 66 COMFIL
70. duty rate is the wider the HIGH pulse is Cycle is a value determining width of one cycle If it is omitted it becomes 255 In case of PB series you cannot adjust a value of cycle and the value is fixed 255 Only port 9 and port 10 can be used for PWM output PWM instruction keeps outputting PWM waveform until power off or PWMOFF instruction Duty rate lt P Cycle You can change the cycle of PWM waveform by adjusting cycle The following table shows the relation between cycles and cycle of PWM waveform Days res 28 4KHz 255 122KHz 0 1023 Range of duty rate changes in accordance with variation of cycle Input range of duty rate cannot exceed quadruple cycle value If it exceeds an appropriate port becomes HIGH state Make certain that a changed cycle value will affect both port 9 and port 10 you cannot use different cycle value at port9 and port 10 In case of PB series you cannot adjust the cycle value It is fixed as 255 Frequency of each model is as the following table Frequency 256Hz Frequency 1 22KHz Frequency 1 22KHz 8bits resolution 8bits resolution 8bits resolution If you want to output wave having different frequency in PB series you should use FREQOUT instruction You cannot use FREQOUT instruction in PBM series You can same result as FREQOUT instruction by adjusting a cycle value of PWM instruction EXAMPLE 10 0 Store the result of A D input at PW
71. e Day About PICBASIC Studio CONST DEVICE Run Break Verify Syntax Check View Object code View Label List execute SyntaxCheck compile and download in tum stop execution and start Debug mode compare source code check syntax error display Object code display label list View PICBASIC Flash Memory display content of PICBASIC module Check Variable Modify Variable Clear Flash Memory Use Korean Menu Editor Environment Printer Port Setup Help Tip of the Day check value in specific variable modify value in specific variable clear content of PICBASIC module change language into Korean show Editor setup change address of printer port and set Rev B cable Open PICBASIC manual About PICBASIC Studio display version When you work in PICBASIC studio You must let PICBASIC studio what kind of device you work with by declaring in the first part of your program with CONST DEVICE as follows CONST DEVICE R5 Please refer to Chapter 2 Instructions for details about CONST DEVICE COMFILE Technology 33 PICBASIC DATABOOK EDITOR FUNCTION KEYS The following function keys can be available in Editor state BLOCK CONTROL FILE CONTROL 34 UP DOWN arrow LEFT arrow RIGHT arrow Ctrl UP arrow Ctrl DOWN arrow Ctrl LEFT arrow Ctrl RIGHT arrow Home End Ctrl Home Ctrl End PgUp PgDn Ctrl F Ctrl Z SHIFT ar
72. e to save it in the forms of BAS file If you need to protect your source code you should save only Object code from your source file Because none can read your source file from the Object code file you can keep your source file safe EDIT MENU Undo Ctrl z Redo Ctrl Cut Ctrl X Copy Ctrl C Paste Sellect Ctrl amp SEARCH MENU Find Ctrl F Find Next Find Previous Ctrl F3 Replace Ctrl H Goto Line Ctrl G Toggle Bookmark Next Bookmark Previous Bookmark Bookmark clear all 32 Undo cancel previous work Redo execute previous cancellation Cut cut marked text and place in clipboard Copy copy marked text to clipboard Paste paste clipboard text at cursor Select All select all Find find text Find Next find next occurring text Find Previous find previous occurring text Replace replace marked text Goto line move cursor to specific line Toggle Bookmark mark bookmark Next Bookmark move to next bookmark Previous Bookmark move to previous bookmark Bookmark clear all clear all bookmarks COMFILE Technology PICBASIC DATABOOK RUN MENU Run F5 Break F6 Verify F4 Syntax Check View Object Code F8 View Label List View PICBASIC Flash Memory Steck variable vaname Clear Flash Memory SETUP MENU Use Korean Menu Editor Environment Printer Port Setup HELP MENU Help Tip of th
73. e variable The maximum value is 127 Label is a label or line where to jump to EXPLANATION This instruction jumps to a label where a parameter indicates If the parameter is 0 then it jumps to label 1 and if the parameter is 1 it jumps to label 2 EXAMPLE ON I GOTO 100 200 300 When 150 jumps to 100 When 1 1 jumps to 200 When 2 jumps to 300 When is other value executes next line without jump 92 COMFILE Technology PICBASIC DATABOOK ON GOSUB ON parameter GOSUB label1 label2 label3 Call subroutine by parameter Parameter is a Byte variable The maximum value is 127 Label is a label line of subroutine where to be called EXPLANATION This instruction calls subroutine by parameter When the parameter is 0 then it calls lable1 when 1 calls label2 you can use up to 127 label When it encounters RETURN it is back to next line of ON GOSUB instruction EXAMPLE ON GOSUB 100 200 300 When 0 call address 100 When 1 call address 200 When 2 call address 300 When is other value executes next line without call COMFILE Technology 93 PICBASIC DATABOOK ON INT GOSUB ON INT edge GOSUB label Ports interrupt Edge is a constant 0 or 1 Label is a label line of subroutine where to be called EXPLANATION When rising falling edge is detected at port 8 of PBM series this instruction calls specific label If the edge set 0 a fa
74. eads data from buffer not read data from RX pin directly A circuit for receiving storing RS232 data from RX pin should work constantly by using SET RS232 instruction at the first part of a program 78 COMFILE Technology PICBASIC DATABOOK GOTO GOTO label Unconditional jump Label is where to jump EXPLANATION This instruction makes program jump to specified line number or label EXAMPLE GOTO 10 Jump to label 10 ADDITIONAL INFORMATION There are two kinds of identifiers line number and label used to point a specific area of a program Line number is what we call a kind of label consisting of numbers 10 PRINT GOTO 10 Label is suitable for subroutine s name etc It must start with an alphabet and finish with colon GOSUB DELAY10 DELAY10 FOR 1 0 TO 10 NEXT I RETURN You can use up to 255 of characters for name of jump label Valid label Invalid label NOKEY 123AB Started with digit DELAY RTN IN Name of instruction PROC COMFILE Technology 79 PICBASIC DATABOOK GOSUB RETURN GOSUB label RETURN Call subroutine Label is a subroutine line where to jump EXPLANATION This instruction calls subroutine and returns EXAMPLE 10 GOSUB DELAY 10 Call subroutine DELAY10 GOTO 10 DELAY 10 FOR 150 10 NEXT I RETURN Returns after subroutine DELAY 10 ADDITIONAL INFORMATION Because PICBASIC modules have limited stacks it is im
75. ery 20 interval The motor rotates faster COMFILE Technology 125 PICBASIC DATABOOK Pulse interval means one cycle of pulse The smaller the value of interval is the shorter a pulse is a motor rotates faster The larger the value of interval is the longer a pulse is A motor rotates slower The following table shows pulse interval of each PICBASIC module Pulse interval 1 255 1B 1S 28 2H 3B 3H ist It is possible to stop during operation When stop port become LOW or HIGH outputting pulse is stopped 8 8 aS 9 STEPOUT 2 10 500 3 0 Output wave 500 times every 10 interval If port3 becomes LOW during operation stop outputting 126 COMFILE Technology PICBASIC DATABOOK TABLE Table parameter value1 value2 value3 Converting table Parameter is a Byte variable Its value must not exceed 127 Value is a constant 0 255 EXPLANATION This instruction executes table conversion by a parameter When a parameter is 0 it returns value 1 when a parameter is 1 it returns value 2 Number of value is available up to 127 and must 8bits value 0 255 EXAMPLE TABLE J 192 22 165 9 34 If J 0 1 192 If J 1 1 22 If J 2 1 165 If J 3 1 9 If J 4 1 34 If J is other value 0 TOGGLE TOGGLE port Invert output state Port is a constant 90 31 or a Byte variable specifying port number EXPLANATION This instruction inverts state of a s
76. es as the following picture and connect a LCD module to a receiver module PICBASIC PICBASIC Sender Receiver Input the following program into a sender module Sending program CONST TX PIN 0 CONST BAUD 103 DIM AS BYTE 10 SEROUT TX PIN BAUD 0 1 PICBASIC DELAY 1000 GOTO 10 Input the following program into a receiver module and execute Then you will see PICBASIC on the LCD Receiving program CONST RX PIN 0 CONST BAUD 103 DIM AS BYTE DIM A 10 AS BYTE SET PICBUS HIGH 10 SERIN RX PIN BAUD 0 5000 10 A 0 8 0 7 LOCATE 1 0 PRINT NEXT I GOTO 10 This program as a simple example for communication between PICBASIC modules makes the sender module to send data every one second and makes the receiver to stay at waiting state display received data instantly However because that actual programs add the receiver various function the receiver can not be waiting state for RS232C signal all the time Therefore there needs a trick to make the receiver Because SERIN instruction does not have buffer function it can receive data incoming right after its execution Therefore receiver s program should inform a RS232C sender through extra I O pin when it is ready to receive data This is called Flow control The sender s program watches an assigned pin for Flow control and sends data when it receives a signal from the receiver If the sender s program should execute other
77. for 5 OUT RELAYPORT 1 You can understand at once that RELAY turns ON You can express Single data in characters as well as Integer data CONST PIE 3 14 Single data as constant DIM K AS SINGLE K PIE Array You can also define Byte type one dimensional array up to 65535 elements in PICBASIC DM A 20 AS BYTE Define 20 of A array DIM B 200 AS INTEGER Integer array DIM C 200 AS LONG Longarray DIM D 200 AS SINGLE Single array Parameter of array starts from 0 Therefore when 20 elements are defined you can use from 0 to 19 Because that PB modules have limited size of data memory maximum definition range of array is same as size of data memory i e PB 1S has 96bytes of data memory Therefore it is possible to use array up to 96bytes You cannot use array as parameter of array as follows ARRAY K J 40 COMFILE Technology PICBASIC DATABOOK Bit designator It is possible to access specific bit of variable by bit pointer Bit pointer is available from 0 to 31 Bit pointer of each variable type is as follow PB series use dot as bit pointer while PBM series use colon Bit pointer is not available with Single variable BYTE INTEGER 15 14 113 12 11 10 9876543210 LONG 313029 28 272625 24 23 2221 2019 1817 161514 13 121110 9 8 7 6 54 3 2 1 0
78. g buffer of RS232C Shift input for SPI communication Shift output for SPI communication Analog I O instructions 46 ADIN PWM PWMOFF DACOUT Read AD conversion value Output PWM wave Stop output of PWM wave Output PWM wave for D A conversion during specific period 8bit COMFILE Technology PICBASIC DATABOOK Sound instructions SOUND Generate semplice sound BEEP Generate key touch sound PLAY Play music LCD control instructions LCDINIT Initialize a LCD CLS Clear LCD screen LOCATE Appoint location of display PRINT Display capital or digit CSRON Turn a cursor ON CSROFF Turn a cursor OFF BUSOUT Transmit specific code to PICBUS SET PICBUS Change transmission speed of PICBUS to 19200 or 4800 baud rate EEPROM access instructions EEWRITE Write data at specific location of EEPROM EEREAD Read data from specific location of EEPROM Interrupt instructions ON TIMER GOSUB Execute specific routine periodically ON INT GOSUB Execute specific routine by generating edge at port 8 Fem GOSUB Execute specific routine by interrupt of hardware RS232C Fem ONTIMER ON OFF Timer interrupt ON OFF Fem ONINT ON OFF Edge interrupt of port 8 ON OFF Fem SET ONRECV ON OFF RS232C receiving interrupt ON OFF Key input instructions ADKEYIN Receive key input by A D conversion PADIN Read keypad 4 4 key matrix Fem Read keypad 8 8 key matrix KEYIN Read
79. g example is for counting of pulse incoming from CLKIN during specific period DIM AS INTEGER 10 1 COUNT 1 Clear count value DELAY 100 Delay for 100mS COUNT 1 Store incoming pulse for 100 LOCATE 0 0 PRINT Display the result on LCD GOTO 10 Repetition COMFILE Technology 63 PICBASIC DATABOOK CSNG Single variable CSNG value Convert Integer type to Single type Value is a Byte Integer and Long constant variable EXPLANATION This instruction converts Byte Integer Long constants variable into Singer constants variable Because that PICBASIC language does not allow operating Single value and Byte Integer Long value together in a operation you should temporary convert Byte Integer Long value into Single value by this instruction EXAMPLE An operation on line 6 in the following program is combined with Single variable and Long variable DIM L1 AS LONG DIM 1 AS SINGLE DIM S2 AS SINGLE 1 1234 5678 333 2 1 1 Therefore the result of this operation is not predictable and the operation must be corrected as follows DIM L1 AS LONG DIM S1 AS SINGLE DIM S2 AS SINGLE 1 1234 5678 L1 333 2 1 CSNG L1 411 should be applied to this operation after converting into Single type All constants used with Single value in an operation must have POINT as follow 2 81 CSNG L1 3 0 64 COMFILE Technology PICBASIC DATABOOK CSRON CSRON Tum on LCD
80. g method receiving data from RX terminal while another routine is processing GET instruction can read data by FIFO First in First OUT SERIN another instruction for receiving RS232C by using software half duplex method has no RS232C buffer Therefore it can read data only while the instruction is processing Refer to Depth analysis of RS232C for the details of difference between GET instruction and SERIN instruction Delay is time to wait for incoming data when there is no data in RS232C buffer If there is no data after delay a program jump to where jump label indicates If you don t give jump label specific value the program goes to next line If the incoming data comes continuously you can receive it to String variable EXAMPLE SET RS232 9600 Initialize hardware RS232C at 9600 baud rate DIM AS BYTE GET 1 100 Receive data for 100 5 in waiting state If no receipt go to next line GETI receipt of data store it at 1 otherwise go to next line 1 100 Receive data for 100 5 in waiting state If no receipt go to ERR ADDITIONAL INFORMATION Both GET instruction and PUT instruction uses hardware RS232C port The hardware RS232C has 96bytes of receiving buffer When the buffer is used up with data it overwrites from the first parts of buffer Therefore the data in the receiving buffer must be read before the buffer is full by GET instruction For this uses ON interrupt function GET instruction r
81. garithmic value of a single constant variable A constant variable which will be inputted into blank must be single type Otherwise the constant variable must be converted into single type EXAMPLE DIM F1 AS SINGLE F1 LOG 1 0 LOG10 FETI Single variable LOG value Common logarithmic function Value is a Single constant variable EXPLANATION This instruction returns the common logarithmic value of a single constant variable A constant variable which will be inputted into blank must be single type Otherwise the constant variable must be converted into single type EXAMPLE DIM F1 AS SINGLE F1 LOG10 1 0 90 Technology PICBASIC DATABOOK MID String variable MID string point length Cut string String is a String variable Point is a constant 0 31 or a Byte variable where to be cut from Length is a constant 0 31 or a Byte variable to be cut EXPLANATION This instruction cuts desired length from an appointed point in the middle of a string Point is in order of 1 2 3 from left For instance When a string ST is ABCDEFG MID ST 2 3 results BCD EXAMPLE DIM ST AS STRING 16 Set 16 the maximum length of string DIM RE AS STRING 16 ST I LOVE YOU RE MID ST 3 4 LOCATE 0 0 PRINT RE LCD displays LOVE COMFILE Technology 91 PICBASIC DATABOOK ON GOTO ON parameter GOTO label1 label2 label3 Branch by parameter Parameter is a Byt
82. gle type COMFILE Technology 49 PICBASIC DATABOOK ADIN Integer variable ADIN port A D conversion Port is an Integer variable constant 0 33 acceptable A D input EXPLANATION This instruction which is for receiving input of A D conversion converts analog value inputted at appointed port into 8 10bits of digital value 0 255 or 0 1023 and return the digital value Converting OV 5Vof voltage inputted into digital value For instance in case of 106 conversion it will be OV to 0 5V to 1023 and 2 5 to 512 Output 1023 Input Voltage EXAMPLE 0 Execute A D conversion at port 0 and store the result at variable SEROUT 8 93 0 0 I Transmit the result to RS232C ADDITIONAL INFORMATION PBM R5 has extra 12bit A D input port When you use ADIN instruction with port 32 and port 33 12bits A D conversion is executed 0 4095 DIM K AS INTEGER Define as Integer variable 16bits ADIN 32 Execute 1261 A D conversion at port 32 and store the result at Port 32 and Port 33 cannot be used as general I O they are used for only 12bits A D input means the result of this instruction becomes Integer type 50 COMFILE Technology PICBASIC DATABOOK The following pictures show A D input port of each PICBASIC modules PB 1B 15 02 02 C 6 03 AD3 7 04 AD4 8 I O1 AD1 l O2 AD2 l O4 AD4 l O5 AD5 6 6 l O7
83. is a constant 0 31 or a Byte variable indicating port number Value is a constant 0 or 1 or Byte variable EXPLANATION This instruction outputs HIGH or LOW to specific port When value is 0 it outputs LOW When value is 1 it outputs HIGH EXAMPLE OUT 0 1 Make porto HIGH OUT 0 0 porto LOW STATE OF PORT OUTPUT The ports of PICBASIC module flow around 25 in state of output i e when the ports are at output state they can receive 25mA of current Sink current while when the ports are at input state they can output 25mA of current Source current rh Output current from a port Input current into a port 20mA of current is not enough to drive directly devices such as relay solenoid etc In this case you had better amplify the output signal by using a photo coupler or TR as the following picture H Single Board Computer H DC24V Ua 1 PICBASIC oe R1 1 COMPILE 77 98 COMFILE Technology PICBASIC DATABOOK OUTSTAT OUTSTAT port Verify output state Port is a constant 0 31 or a Byte variable indicating port number EXPLANATION This instruction reads current outputting value IN instruction convert appropriate port into input port and read a state of the pin OUTSTAT instruction reads a value in a output buffer This instruction is mainly used to verify an outputting value EXAMPLE OUTSTAT
84. layed on a LCD If you want to display digits in the forms of decimal or hexadecimal use conversion instruction such as DEC or HEX EXAMPLE LOCATE 0 0 PRINT I LOVE PICBASIC PRINT COMFILE amp H30 Example of ELCD162 COMFILE Technology 105 PICBASIC DATABOOK PULSE PULSE port pulse width PULSE port Output pulse Port is a constant 0 31 or a Byte variable indicating port number Pulse width is time of microsecond unit and is an Integer constant 0 65535 variable EXPLANATION This instruction outputs pulse to specific port as long as given pulse width In effect it inverts pulse as long as given Pulse width and returns Pulse width can be omitted When it is omitted it becomes 18 PBM series use PULSE instruction to drive a RC servomotor by adjusting pulse width PB series cannot adjust pulse width it outputs around 2 3 constantly EXAMPLE OUT 3 0 PULSE 3 30 30uS OUT 3 0 PULSE 3 100 100 5 OUT 3 0 0 TO 2 Output pulse three times PULSE 3 100 DELAY 2 NEXT 100uS 100uS 100uS 2 5 5 2 5 5 Above example is program outputting pulse three times As 2 of DELAY instruction is used at LOW state there is needed additional 0 5 mS to execute FOR NEXT instruction 106 COMFILE Technology PICBASIC DATABOOK PUT PUT data Output RS232C data Data is a Byte constant variable or a String constant v
85. lling edge HIGH LOW will be detected Contrary if the edge set 1 a rising edge LOW HIGH will be detected The instruction is a kind of port interrupt by Basic language so as to match variation of a port expeditiously The instruction can be used only once in the first part of a program Not available to use the instruction more than one time simultaneously EXAMPLE ON INT 0 GOSUB 10 While a program runs if a falling edge occurs at port 8 label 10 will be called ON INT 1 GOSUB 10 While a program runs if a rising edge occurs at port 8 label 10 will be called REFERENCE The port 8 of PBM series is specially designed to detect a edge It is impossible to use other ports to detect an edge Though PB series has ON INT instruction also there are differences from PBM series in grammar Interrupt of PBM series can only detects variation of edges It is impossible to detect level by interrupt of PBM series 94 COMFILE Technology PICBASIC DATABOOK ON INT GOSUB ON INT port level GOSUB label Ports interrupt Port is a Byte variable or a port number 0 31 which is able to receive interrupt input Level is a constant 0 or 1 Label is a label line of subroutine where to be called EXPLANATION This instruction reads state of a port and executes specific routine if the state is matched with given condition The instruction is a port interrupt function by Basic language and is used to response variation of por
86. lowing picture shows waveform of RS232C Fixed at 8bit 1 Stop bit None Parity Start bO bi 62 63 64 65 b 67 Stop The instruction is almost same as hardware PUT instruction It has additional advantages such as setting port inverting output and setting delay between bytes Each model has its transmission speed The following table shows transmission speed of each model in accordance with baud rates Baud rate Transmission speed Transmission speed Transmission speed 1 15 25 2H 3B 3H PBM R1 R5 114 COMFILE Technology PICBASIC DATABOOK EXAMPLE SEROUT 3 196 0 1 amp HAO Output to port 3 4800 baud rate non parity interval 1milisecond SEROUT 1 93 1 0 PICBASIC 2000 13 10 Output to port1 9600 baud rate non invert no interval String output ADDITIONAL INFORMATION When you need to send only ASCII code use converting instruction such as DEC HEX etc for converting digits into ASCII code SEROUT 1 93 1 0 DEC I Send value of by decimal SEROUT 1 93 1 0 HEX I Send value of by hexadecimal When Sting variable is used all content of String variable is sent DIM ST AS STRING 16 ST PICBASIC 2000 SEROUT 1 93 1 0 ST PICBASIC 2000 is sent COMFILE Technology 115 PICBASIC DATABOOK SERVO SERVO port position Generate RC SERVO motor control signal Port is a constant or a Byte variable specifying port number 0 31 Position is a constant or a Byte va
87. nd It is different to express constants in PICBASIC language according to scale notation Decimal 10 20 32 1234 Hexadecimal amp HA amp H1234 amp HABCD Binary amp B10001010 amp B10101 You can use lower case letter in PICBASIC However make certain that the compiler of PICBASIC language cannot discern lower case letters i e PICBASIC compiler recognizes lower case letters as capital letters If you use lower case letters and capital letters together the compiler recognizes all of them as capital letter only For a instance LoopCNT is recognized as LOOPCNT Name of variables must start with a English character and must have less size than 255 characters You cannot use name of command and function as name of variable Valid variable name J TH BF 1 Invalid variable name 23 3A INPUT GOTO Declaration of variable must be placed at the first part of program just as followings DIM AS BYTE Delimiting as BYTE type DIM J AS INTEGER Delimiting J as INTEGER type DIM AS BYTE J AS BYTE COMFILE Technology PICBASIC DATABOOK Variable type PICBASIC language uses five types of variable PB series can use only two types of variable BYTE type and INTEGER type while PBM series use all five types of variable Byte 8bit number without sign 0 255 Integer 16bit number without sign 0 65535 Long 82bit number with sign 2 147 483 648 2 147 483 647 Single 3
88. ne The instruction can be used only once in the first part of a program Not available to use the instruction more than one time simultaneously EXAMPLE ON RECV GOSUB 10 During operation of program if RS232C data is received jump to line10 10 GETI Get one byte from buffer 96 COMFILE Technology PICBASIC DATABOOK ON TIMER GOSUB ON TIMER interval GOSUB label Time interrupt Interval is a constant 0 20 indicating interval of interrupt Labelis a label line to be called when an interrupt occurs EXPLANATION This instruction performs specific routine indicated by label every interval The instruction is a kind of Time interrupt function by Basic language The instruction can be used only once in the first part of a program x o ae s o s ouem EXAMPLE ON TIMER 0 GOSUB 10 In case of PBM Rx call line10 every 10 seconds ADDITIONAL INFORMATION When you use ON TIMER instruction you make sure that a subroutine which is called by label must finish its execution within specific interval If a subroutine having one second interval has two seconds of execution time the subroutine will not operate properly and not make desired result Therefore you must make execution time of a subroutine less than a period appointed by interval COMFILE Technology 97 PICBASIC DATABOOK OUT OUT port value Port output Port
89. nsmission A g 1 1 1 1 STOP START 1 0 1 0 1 0 1 0 STOP STARTO 0 0 0 Hexadecimal 55 Binary 01010101 0 11110000 In above picture a RS232C sender outputs HIGH signal in waiting state If transmission starts the sender outputs LOW signal This is TTL level 0 5 of RS232C transmission and is called Positive logic In actual application of RS232C such as PC and so on RS232C adopts Negative true logic and 12 of level in order to reducing bad influence of noise in long distance transmission 5V mui gt Start bO b1 b2 b4 b5 b6 b7 Stop Start b0 b1 b2 b3 b4 b5 b6 b7 Stop 10V 10V 136 COMFILE Technology PICBASIC DATABOOK Therefore there needs an additional circuit for converting these 12 Negative true logic RS232C signal into 5V positive logic RS232 signal MAX232 is most commonly used chip for this work You can find the 232 chip in most of RS232C circuit PICBASIC PnP board also contains MAX232C and its circuit is as follows PC RS232C Port 0 1uF 0 1uF 0 1uF L 232 is a kind of inverter operating in different voltage levels TTL level is 0 5V range 1 2 2 E 5 O 7 N 8 RS232C OUTPUT 7 RS232C INPUT 8 COMFILE Technology 137 PICBASIC DATABOOK Communication between PICBASIC To make RS232C communication between PICBASIC modules connect port 0 port 16 and GND of two PB 3B modul
90. nstructions OSCIN OSCOUT must be connected to 20 2 crystal RES pin should be connected to 5V without additional circuit The picture shown below is basic circuit for operating PB 3B module 5 10K RES PCOUT I O0 ADO PCIN lI O1 AD1 l O2 AD2 1 03 AD3 PICBUS 10K 1 07 1 06 1N4148 gt OANDOABRWDN 9 05 04 4 9 1017 GND Oo 1 016 OSCIN 07 0 tuF OSCOUT i mE 2 22pF 1 08 1 015 22 09 014 e I O10 PWM1 013 25 e 011 012 PRINTER PORT COMFILE Technology 15 PICBASIC DATABOOK PB 3H RES PCOUT 00 I O1 AD1 PICBUS 02 2 1 028 1 03 AD3 1 027 CLKIN 1 026 1 04 AD4 1 025 I O5 AD5 1 024 1 06 AD6 5V 1 07 AD7 GND 5V 1 023 GND 1 022 OSCIN 1 021 OSCOUT 1 020 1 08 1 015 I O9 PWM0 1 014 1 010 PWM1 1 013 1 011 1 012 1 016 1 019 1 017 1 018 Por block s o O o s 055 Pos Tr s e p Pes 2 o G o oscour 4 a ST PWMpot PWM port PWM port 16 COMFILE Technology PICBASIC DATABOOK x wm m s 5 won emm st wm wz Bex St mm St sw Sem j 1 x Pes
91. nversion STEPOUT Use PULSE and FOR NEXT instruction FREQOUT Adjust frequency value of PWM instruction KEYDELAY Use DELAY instruction DIFFERENT USAGE BETWEEN PB SERIES AND PBM SERIES Additional function FOR NEXT STEP is available 128 127 EEWRITE Assigning byte number for WRITE is available EEREAD Assigning byte number for READ is available PWM Adjusting cycle value is available PULSE Adjusting length of pulse when omitted 1mS DELAY Delay up to 65535mS PB series is 255 5 CUT OFF FUNCTION IN PBM SERIES Additional function Excludes control statement SKIP and UNTIL Only Edge interrupt is detectable at port8 excludes check function for level variation ETC Variable Add LONG type STRING type SINGLE type Array Extended Subscript 0 65535 Bit Byte designator DOT COLON SET PICBUS Initial value is HIGH 19200 baud rate 132 COMFILE Technology PICBASIC DATABOOK Chapter 3 PICBASIC Programming PICBASIC DATABOOK RS232C Advanced analysis When programming in PICBASIC you will encounter the situation needing interface with other devices Most common interface is very RS232C communication It is widely used in PC as well as other devices such as card reader small size printer display etc PICBASIC language includes various instructions for RS232C the instructions are SERIN SEROUT PUT and GET There also are instructions for dealing with re
92. ogy 85 PICBASIC DATABOOK KEYDELAY Integer variable KEYDELAY key function value delay1 delay2 Key input delay Key function is one of ADKEY KEYIN and PADIN Value is a constant and value to be returned normally 0 when there is no input Delay is a constant 0 255 and wait time for repeat Delay2 is a constant 0 255 and repeat time EXPLANATION This instruction sets delay of key input Key instruction can be one of ADKEYIN KEYIN and PADIN The result of this instruction is same as the result of Key instruction The instruction just makes delay specified by Delay and Delay2 to return the result The instruction is not available in PBM series EXAMPLE 10 KEYDELAY KEYIN 0 1 30 10 In case of KEYIN IF 1 THEN GOTO 10 If there is key input then executes here GOTO 10 10 KEYDELAY ADKEYIN O 0 30 10 In case of ADKEYIN IF 0 THEN 10 If there is key input then executes here GOTO 10 LOCATE 0 0 PRINT DEC I GOTO 10 10 KEYDELAY 0 0 30 10 In case of PADIN IF 0 THEN 10 If there is key input then executes here LOCATE 0 0 PRINT DEC I GOTO 10 86 COMFILE Technology PICBASIC DATABOOK LCDINIT LCDINIT Initialize LCD EXPLANATION This instruction initializes LCD including data on a display LEFT String variable LEFT string value Cut string from left String is a String variable Value is a Byte constant variable
93. or download from download section of www comfile co kr english INSTALLATION To program PICBASIC modules it is essential to install PICBASIC studio and to make connection between a PICBASIC module and your PC with a PICBASIC cable To install PICBASIC studio into your PC please follow below steps Step 1 Insert COMFILE program CD into CD drive of your PC In a moment the following screen will appear on your PC The screen may be different in according to CD version DE PUE LAW EID BHAT g P 92 02 4127 S ZI e restes Jera e Ber 202 ICHEO 5275 CD vot OF k FRENCH 2 Met new 914g vv 9 2059 22580 Ser ze ty qi COMPILE MAN ISK 0071 2833 COMFILE Technology 27 28 PICBASIC DATABOOK Step 2 On the screen click ENGLISH then you will see pages written in English In the page select download Tab heraa Meten Cac 1 pevne VOLADA Ji 51011499 Fa eaa n esset Lao m ET T LANG oven wama Il pun Click PB Qata O we Mi Qn MICA QOO dew d PORA RU rS Toni LAS VE Devetopewt sapiat WT gt COMFILE Technology PI
94. package you don t have to install it separately If you don t allocate LPT1 to HP Laser jet 4 you will encounter the error message as PICBASIC module not found COMFILE Technology 29 PICBASIC DATABOOK GETTING START WITH PICBASIC STUDIO The following screen is initial state of PICBASIC studio Title bar shows current work file and its path PICBASIC Studia 9 doacumentstWtest bas 1 Edit Search Run Setup Help 4 Ve X30 Tool bar is consists of icons which indicate most frequent used function Status bar shows size of source code current working line number and status of modification zi ins You program your source just as typical word process editor Do not forget to save your source after programming it Vd Sae QUO ORO SSO VP x ES So lt S SOM o K SF lt lt gt 30 COMFILE Technology PICBASIC DATABOOK When you finish programming saving your source click Run button as below in order to execute the source Run will check Syntax error in your source and if no error is found download the source into PICBASIC module While those two processes if there occurs no error the PICBASIC module is ready to execute the source Te gm Bun Setup Help na E TEST FOR R8232 COMMUNICATION P3 CONST DEVICE R5 SET 8232 96000 Click here Ln 10 Col 12 Lines 1
95. pecific port i e LOW to HIGH and High to LOW EXAMPLE OUT 0 1 Make porto HIGH FOR 0 TO 7 TOGGLE 0 Invert porto NEXT I OUT 0 0 Make porto LOW COMFILE Technology 127 PICBASIC DATABOOK TIME TIME address Read real time data Address is a constant or a Byte variable specifying address number EXPLANATION PBM R5 module has a built in real time clock chip 051302 The chip has a dedicated clock crystal 32 768 KHz and can renewal automatically second minute hour day month and year The chip has several memory blocks Each block contains data of second minute hour and so on in the forms of BCD code The data will be read by TIME O Send 59 11 1 Mme 0859 to 11 2 mr ooo OO 11 Dae MEME 0 111 42 col 5 _ L 6 Yw 11 EXAMPLE SS TIME 0 Read current second MM TIME 1 Read current minute HH TIME 2 Read current hour LOCATE 0 0 PRINT HEX SS Because of BCD value expressed by HEX function ADDITIONAL INFORMATION PBM R5 has built in super condenser 0 1F for real time backup This condenser is charged during operation When PICBASIC module is in OFF state it operates as battery If it is full charged it will last around six months This instruction is available in only PBM R5 128 COMFILE Technology PICBASIC DAT
96. pecification and function of devices mentioned in this data book may be changed without notice to improve their function and performance Use of Comfile s products as critical components in life support systems is not authorized except with express written approval by Comfile Comfile does not warranty to use Comfile s product for the purpose which is not instructed in this data book PICBASIC is copyright of Comfile Technology Inc therefore all information regarding PICBASIC cannot be copied or modified or re produced without written agreement of Comfile 2 COMFILE Technology PICBASIC DATABOOK TABLE OF CONTENTS CHAPTER 1 WHAT IS PICBASIC Specification PINOUT and circuit Dimension PnP board i n ia n E e u ee te es PICBASIC studio Key usage Debug CHAPTER 2 PICBASIC INSTRUCTIONS COMFILE Technology 3 PICBASIC DATABOOK SHIFTIN SHIFTOUT CHAPTER 3 PICBASIC PROGRAMMING RS232C advanced analysis 134 RS2920 basic o5 Hose ilU ipo mad 135 RS232C Communication between PICBASIC modules em emen nennen 138 4 COMFILE Technology PICBASIC DATABOOK Chapter 1 What is PICBASIC PICBASIC DATABOOK What is PICBASIC In a word PICBASIC is micro single board computer controlled by the PICBASIC language The PICBASIC language based on BASIC language is developed by Comfile Technology and incl
97. possible to superpose subroutines above maximum depth level It means that you must not call subroutines from inside of a subroutine more than maximum depth level Stack is returning address of a subroutine and 2 bytes of return address is used by one GOSUB instruction It is ok using subroutines in same depth But nesting subroutines over maximum depth causes problem In addition more because PICBASIC doesn t show any error message for this problem you must very careful with nesting subroutines The maximum subroutine depth of PB series is 7 level while that of PBM series is 10 level Retum must be placed on the end of a subroutine jumping to GOSUB If instructions such as GOTO etc terminate subroutine stack will be overflowed in a program Valid subroutine Invalid subroutine GOSUB 1000 GOSUB 1000 2000 1 1 14 Subroutine 1 1 4 Subroutine RETURN GOTO 2000 80 COMFILE Technology PICBASIC DATABOOK HEX HEX value digit indicator Convert an Integer constant variable into hexadecimal string Value is an Integer type constant variable Digit is the maximum up to 8 positional digit that you want to display Default is 4 Indicator determines to place 0 on space or not O display 1 not display Default is 1 EXPLANATION This instruction converts a constant variable into hexadecimal string The instruction is available with only PRINT instruction in PB series while it is able to store the result of con
98. read data from devices such as SPI and so on etc using CLK and DATA A SHIFTIN 3 4 O 8 EXAMPLE SHIFTIN 3 4 0 Port3 outputs clock Port4 receives data input Mode is 0 The result is stored at l DATA COMFILE Technology 121 PICBASIC DATABOOK SHIFTOUT SHIFTOUT CLK port DATA port mode data bit Serial output CLK port is a constant or a Byte variable specifying port number generating clock OUTPUT DATA port is a constant or a Byte variable specifying port number outputting data INPUT Mode 0 Starting with LSB Least Significant Bit 1 Starting with MSB Most Significant Bit 2 Starting with MSB Most Significant Bit Generating ACKNOLOGY Bitis a constant specifying bit number up to 16 Default is 8 EXPLANATION This instruction is for SHIFT output There are three kinds of modes LSB priority MSB priority and SHIFTOUT Mode 2 is used for protocol which needs ACK every 8 bits during transmission EXAMPLE SHIFTOUT 0 1 0 amp H55 0 is clock 1 is data mode 0 and output amp H55 bO b1 b2 b3 b4 b5 b6 b7 DATA 1 0 1 0 1 0 1 0 amp H55 CLK 122 COMFILE Technology PICBASIC DATABOOK SIN Single variable SIN value SIN function Value is a Single constant variable EXPLANA
99. requent shortly PBM series can use the instruction at port 0 15 Single Board Computer Moe C 2000 4 Flash 64K RAM 32K EEPROM 32K 12bit ADC 34 0 2 5 5 TECHNOLOGY EXAMPLE 20 IF KEYIN 1 1 THEN GOTO 20 Receive a key input at port 1 it becomes 0 when pushed BEEP 10 When the key is pushed short BEEP sounds GOTO 20 BCLR BCLR Clear RS232 buffer EXPLANATION This instruction clears buffer of hardware RS232C Buffer of RS232C is cleared on power on After execution of SET RS232C instruction data received at RX pin are saved in RS232C buffer BCLR instruction clears all data in the buffer COMFILE Technology 55 PICBASIC DATABOOK BLEN 0 Integer variable BLEN 0 Number of data at RS232C EXPLANATION This instruction returns number of data received at buffer of RS232C The bracketed 0 is meaningless dummy value EXAMPLE DIM AS BYTE J AS BYTE AS BYTE SET RS232 9600 Activate RS232C at 9600 baud rate ON RECV GOSUB 100 Execute receiving one hundred times OUT 19 0 10 PULSE 19 100 DELAY 100 IF KEYIN 9 0 THEN Clear RS232C buffer when key 9 is pushed BCLR END IF GOTO 10 100 0 Execute ECHO after reading number of data in buffer FORJ 1TOK GET PUT NEXT RETURN BREAK BREAK Break EXPLANATION A program breaks execution on encountering this instruction in executing
100. riable 0 255 EXPLANATION This instructions generates signal to control a RC SERVO motor You can make positioning of a RC SERVO motor simply 1mS 1 5mS 2mS gt gt lt gt 45 0 45 When RC SERVO motor is provided with 1mS of pulse sixty times per a second it is positioned at 45 When 1 5mS it is positioned at 0 When 215 it is positioned 45 RC SERVO motor rotates only within 180 PBM series can t use SERVO instruction To drive a RC SERVO motor in PBM series use PULSE instruction EXAMPLE The following example is for PB 1B 1S 2S Port 0 is used for pulse output DASI SERVO 0 333 Generates 1mS of pulse at port 0 DELAY 10 GOTO DASI Usage of SERVO instruction is little different by each model S PB 1B 1S 2S PB 2H 3B 3H Unit 3uS 0 8uS To generate 1mS of pulse SERVO 0 333 SERVO 0 1250 CAUTION ON SERVO INSTRUCTION RC servo motor needs continued pulse supply sixty times per one second to hold current position Otherwise it cannot hold desired position or if loaded it becomes uncontrollable To provide pulse steadily you had better organize the endless loop shown above example However in case of controlling several RC servomotors simultaneously it may cause problem to control all RC servomotor by software Therefore there needs dedicated controller for RC servomotor such as SMC PRO Comfile Technology 116 COMFILE Technology PICBASIC DATABOO
101. row Ctrl X Ctrl C Ctrl V Ctri A Ctrl X F2 move cursor up one line move cursor down one line move cursor left one line move cursor right one line move cursor up move cursor down move cursor left move cursor right move cursor at beginning of line move cursor at end of the line move cursor at beginning of program move cursor at end of program move cursor one page move cursor down one page Find Undo highlight one character to direction of arrow cut marked text and place in clipboard copy marked text to clipboard paste clipboard text at cursor highlight all Open another file Save current working file COMFILE Technology PICBASIC DATABOOK DEBUGGING BREAK amp CHECK STEP OPERATION While a PICBASIC module is connected with your PC you can execute BREAK at any time Once you execute BREAK PICBASIC studio goes into DEBUG mode and shows DEBUG window as follow The DEBUG window shows location where the execution stop and variable value etc PICBASIC Debug Win Debug Variable Step Into Step Over Step Out Modify Variable Erase Flash Exit FOR RS232 COMMUNICATION CONST DEVICE RS SET R5232 96000 DIM J S BYTE ON RECV GOSUB 100 In the state of Debug mode you can look into variation of variable state of I O etc by executing Step Into In order to restart program click Exit button Only Seep Into
102. rt 16 and allocation of input ports must start from port 24 If you don t use up all ports you can use unallocated ports for other purpose In that case the ports must be input ports only due that they will output undesired result when used as output ports COMFILE Technology T3 PICBASIC DATABOOK EXP Single variable EXP value Compute natural logarithm e Value is a Single constant variable EXPLANATION This instruction returns the natural logarithm of inputted value The value must be a Single variable constant When the value isn t Single type use CSNG function to convert it into Single value EXAMPLE DIM F1 AS SINGLE F1 EXP 2 0 74 COMFILE Technology PICBASIC DATABOOK FREQOUT FREQOUT port parameter Output desired frequency Port is a Byte constant must 9 or 0 variable Parameter is a Byte constant 1 253 variable indicating frequency EXPLANATION This instruction outputs consistently without relation to program process the waveform of desired frequency to specific port It uses PWM port 9 or 10 and keeps outputting the waveform of desired frequency until encountering OFF command of PWMOFF FREQOUT is available in PB series PBM series can get same result by adjusting cycle of PWM instruction EXAMPLE FREQOUT 9 131 Output 1KHz of waveform through port 9 Case of 5G ADDITIONAL INFORMATION The following table shows frequency output of each model
103. s inside of microprocessor and used for storing value of variables Data in SRAM is destroyed when power source is off and is set as 0 when power source is on COMFILE Technology 25 PICBASIC DATABOOK PBM MODULES A PBM R5 module has a FLASH ROM 29C512 64Kbyte as its main memory and has a SRAM 62256 32Kbyte and a EEPROM 24LC256 32Kbyte as its data memory 64K byte FFFF PBM R5 32K byte 32K byte 7FFF 7FFF 0000 0000 0000 Program Memory EEPROM Data Memory 29C512 Flash 24LC256 62256 SRAM A PBM R1 module has a FLASH ROM 29C512 64Kbyte of main memory and has a SRAM 6264 8Kbyte and a EEPROM 24LC64 8Kbyte of data memory The differences between PBM R1 PBM R5 are 12bit A D convert function and real time clock function 64K byte FFFF 1 8K byte 8K byte 1FFF 1FFF ome 0000 0000 Program Memory EEPROM Data Memory 29C512 Flash 24LC64 6264 SRAM Unlike PB modules PBM series modules do not clear content of RAM on RESET Therefore user software should clear content of RAM if needed 26 COMFILE Technology PICBASIC DATABOOK PICBASIC Studio PICBASIC studio is Integrated Development Environment for PICBASIC It includes Compiler Editor Debugger and etc and has similar usage as word processor and is compatible with Microsoft Windows 98 ME NT 2000 XP You can get it fom COMFILE program CD provided with PICBASIC products
104. status of port KEYDELAY Adjust value of delay and repeat on key input Real time instructions Fem TIME Read real time data Set time Location control instructions FREQOUT Generate random frequency Using PWM port CAPTURE Measure cycle of outer wave STEPOUT Output pulse for controlling STEP motor SERVO Control position of RC SERVO motor COMFILE Technology 47 PICBASIC DATABOOK Instructions relating to string Fem DEC Convert constant variable to decimal string Fem HEX Convert constant variable to hexadecimal string Fem FLOAT Convert real type constant variable to real type string Fem LEFT Extract characters from left part of string Fem RIGHT Extract characters right part of string Fem MID Extract characters center part of string ASC Return ASCII code of first character in string Fem CHR Convert constant variable to character Fem VAL Convert digit character of string to value Pem VANSNG Convert real digit character of string to value Instructions relating to mathematical function Fem Retum value of SIN Fem COS Return value of COS ABS Return absolute value Fem Return exponential function Fem LOG Retum value of natural logarithm Fem LOG10 Retum 10 based natural logarithm Fem SQR Return value of square root Fem POW Compute X Conversion instructions Fem
105. t state quickly The instruction can be used only once in the first part of a program Not available to use the instruction more than one time simultaneously EXAMPLE ON INT 0 0 GOSUB 20 While a program executes if port 0 becomes LOW executes line 20 10 GOTO 10 If not in interrupt process executes endless loop 20 OUT 1 1 RETURN REGARDING EDGE INTERRUPT Edges can be detected at a specific port by ON INT instruction Port 5 of PB 1x 2x series port 16 of PB 3B and port 24 of PB 3H are designed to detect edges When those ports are used by ON INT instruction they operate as an edge interrupt The edge interrupt occurs where variation of an edge interrupt port status from LOW to HIGH Rising edge or HIGH to LOW Falling edge is detected EXAMPLE ON INT 5 0 GOSUB 10 While a program executes if there occurs falling edge at port5 call line10 INT 5 1GOSUB 10 While a program executes if there occurs rising edge at port5 call line10 COMFILE Technology 95 PICBASIC DATABOOK ON RECV GOSUB GOSUB label RS232C receiving interrupt Label is a label line to be called when an interrupt occurs EXPLANATION This instruction calls specific label when RX I O 15 receives data while RS232C hardware is used If RS232C receives data while a program operates the program stores the data in extra buffer and read the data from the extra buffer after jumping to specific subrouti
106. ts Row and Ports from 24 to 31 are input ports Column The input ports must be equipped with Pull up resister Around 5k 10k VO 31 3 i VO 30 29 C 28 FORMAE Cy Em a r C 27 y Y y C COP y 26 m Fy 25 CO AOL OLE i VO 24 E 23 64 56 48 40 32 24 16 8 VO 22 63 55 47 39 31 23 15 7 62 54 46 38 30 22 14 6 Ore 61 53 45 37 29 21 13 5 VO 20 60 52 44 36 28 20 12 4 59 51 43 35 27 19 11 3 VO 19 58 50 42 34 26 18 10 2 1648 57 49 41 33 25 17 9 1 SCAN CODE 16 EPADIN 8 8 Read keypad by 8X8 LOCATE 0 0 PRINT Display scan code on LCD 72 COMFILE Technology PICBASIC DATABOOK EXAMPLE In case that the key is less than 8 x 8 you can adjust rows and columns as follows Example 6X5 key matrix input VO 31 VO 30 VO 29 VO 28 C 27 ce f a 26 5 5 25 Ce seco E 4 VO 24 C ra VO 23 VO 22 30 25 20 15 10 5 29 24 19 14 9 4 20 28 23 18 13 8 3 27 22 17 12 7 2 1019 26 21 16 11 6 1 VO 18 TUE SCAN CODE VO 16 EPADIN 6 5 Read keypad by 6X5 LOCATE 0 0 PRINT Display scan code on LCD CAUTION Port allocation must be placed in numerical order Allocation of output ports must start from po
107. udes various single instructions such as ADIN PWM and SEROUT etc to be used in automation control field You can simply make instant use of PICBASIC by connecting to printer port of PC and that there is no need of extra MDS It could be applicable widely in automation control field such as automated machine thermal controller inspection ZIG ROBOT controller data acquaintance device etc HARDWARE OF PICBASIC In case of PB 2S it consists of two key components chip and EEPROM A program programmed by PICBASIC language is converted into intermediate code and stored at EEPROM EEPROM is FLASH type memory conserving its contents without power supplying PlCmicro chip in PICBASIC plays role of a interpreter that translates and executes the program stored at EEPROM PICBASIC contains interpreter program on board Exterior of PB 1S is similar as SIP Single Inline Package and its lower pins are power source pin RESET pin and I O pins PC connection Interpreter chip PB 28 In case of PB 3X family it has different composition There is no need of extra EEPROM in PB 3X family because that the chip used in PB 3X family has built in EEPROM 6 COMFILE Technology PICBASIC DATABOOK However basic elements such as outer oscillation and bypass condenser etc should be composed by users 5V RES 1e PCOUT 1 00 ADO 2 PCIN 1 1 3 PICBUS 1 02 AD2 4 O7 1 03 AD3 5 Jg O6 CLKIN 6 O5 1
108. ut The rated current of the circuit is less than 200mA When current more than 200mA is needed you should use an additional power supply PnP board3 for PB 3X has different power source circuit DC 9 18V IN 7805 5V OUTPUT 2 BRIDGE Lb 4 DCJACK e e CAP NP 77 The following diagram is LED circuit When HIGH LED turns on bU The following diagram is PUSH S W circuit When a switch is pushed it turns LOW state E 5 Various application boards can be used with PnP board such as STEP motor driving module DC motor driving module RTC board and so on For more information on application boards refer to COMFILE Technology catalog or visit www comfile co kr 24 COMFILE Technology PICBASIC DATABOOK MEMORY PB MODULES PB modules have 2K 16K of EEPROM which is used for storing program code or data The EEPROM is connected to a main microprocessor of a PB module through PC protocol 2 wires serial communication standard In case of PB 3X it is connected to its main processor directly Program code is stored from address 0 and unused area after storing program code can be used for storing data EEPROM can keep its content in power off state 3FFF 1FFF FFF 7FF 0 0 0 0 8K 2K 4K 16K PB 1B PB 1S 2 2 PB 3B 3H The other memory is 96bytes of SRAM In case of PB 3X it is 88bytes The SRAM i
109. variable by 8bits Accessing by byte Port block is a unit of combined eight ports PB 1B and PB 1S have two port blocks and PBM series has four port blocks EXAMPLE v 40 e 39 e PICBUS GND e Single Board Computer 38 e O33 ADCH 1 00 ADO 37 e 032 ADCHO VO1 AD1 PI BAS 36 031 102 02 e 35 1 03 AD3 e 029 Port block O 04 33 e 1028 Port block 3 05 05 e 32 e 027 l O6 AD6 e 31 e 026 L 107 407 30 025 x VO8 INT e 12 Flash 64K RAM 32K EEPROM 32K 12bit ADC RTC 34 I O 29 e 1 024 09 e 13 28 e 1023 1 010 PWM1 14 PBM R5 27 1022 1 011 15 26 e 1 021 Port block 1 1012 16 25 1020 Port block 2 013 17 24 019 014 18 23 e 1 018 O15 RX e 19 22 e 1 017 CLKIN 20 TECHNOLOGY 2 Vots DIM I AS BYTE Declare as Byte variable 0 Read the state of port block 0 CAUTION Because port blocks which BYTEIN instruction is used in are in input state you cannot assign an output port at the port blocks i e you must use the eight ports assigned to the port block as input port 58 COMFILE Technology PICBASIC DATABOOK BYTEOUT BYTEOUT port block value Output by byte Port block is a port block number and is a constant 0 3 or a Byte variable Value is a constant 0 255 or a Byte variable EXPLANATION This instruction output v
110. version in string variable in PBM series EXAMPLE This is the result of HEX instruction when variable A has amp HABCD b is substituted for space Operation Result PRINT HEX A ABCD PRINT HEX A 8 BbbbABCD PRINT HEX A 8 0 0000ABCD PRINT HEX A 3 BCD PBM series is able to save the result of HEX instruction in a string variable If you use a Long variable positional number must be eight 8 to express the result completely DIM ST AS STRING 16 Set maximum length of string 16 DIM I AS LONG amp H1234ABCD ST 1 8 If digit 8 is omitted result is ABCD COMFILE Technology 81 PICBASIC DATABOOK IF THEN IF expression THEN ELSE Conditional statement EXPLANATION If an expression is true lines of program below THEN executes If the expression is not true lines of program after ELSE execute EXAMPLE IF statement has two types of line form they are one line form and multi line form One line form is completed within one line In one line form command appears after THEN IF 1510 THEN GOTO 10 Jump to address 10 if is larger than 10 IF 1 10 THEN J 20 ELSEJ 30 Put 20 into J if I is 10 otherwise put 30 into J Multi line form has no command after THEN and must be used with END IF Multi line form can use ELSEIF IF gt 99 THEN J ADIN 0 When l is larger than 99 ELSE J ADIN 1 When l is same as 99 or smaller than 99 END IF

Download Pdf Manuals

image

Related Search

Related Contents

AQua-Master - UMAREX GmbH & Co.KG  CHEMINSTRUMENTS HOT ROLL LAMINATOR MODEL HL    Que de conformidad con el artículo 1 del Decreto 3576 de 2009, el  

Copyright © All rights reserved.
Failed to retrieve file