Detailed instructions for use are in the User's Guide.
[. . . ] mikroElektronika
Development tools - Books - Compilers www. mikroe. com
User's manual
BASIC Compiler for Microchip PIC microcontrollers
mikroBASIC
Making it simple
mikro
IN-CIRCUIT
ICD
Develop your applications quickly and easily with the world's most intuitive BASIC compiler for PIC Microcontrollers (families PIC12, PIC16, and PIC18). Highly sophisticated IDE provides the power you need with the simplicity of a Windows based point-and-click environment. With useful implemented tools, many practical code examples, broad set of built-in routines, and a comprehensive Help, mikroBasic makes a fast and reliable tool, which can satisfy needs of experienced engineers and beginners alike.
DEBUGGER
SUPPORTED from V5. 0
mikroBASIC
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
making it simple. . .
Reader's note
DISCLAIMER: mikroBasic and this manual are owned by mikroElektronika and are protected by copyright law and international copyright treaty. Therefore, you should treat this manual like any other copyrighted material (e. g. , a book). [. . . ] See Cf_Fat_Rewrite or Cf_Fat_Append.
Example
Cf_Fat_Set_File_Date(2005, 9, 30, 17, 41, 0)
page
mikroElektronika: Development tools - Books - Compilers
137
mikroBASIC
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
making it simple. . .
Cf_Fat_Get_File_Date
Prototype
sub procedure Cf_Fat_Get_File_Date(dim byref year as word, dim byref month as word, dim byref day as word, dim byref hours as word, dim byref mins as word)
Returns Description Requires
Nothing. See Cf_Fat_Assign.
Example
Cf_Fat_Get_File_Date(year, month, day, hours, mins)
Cf_Fat_Get_File_Size
Prototype Returns Description Requires
sub function Cf_Fat_Get_File_Size as longint
Size of file in bytes. See Cf_Fat_Assign.
Example
Cf_Fat_Get_File_Size
page
138
mikroElektronika: Development tools - Books - Compilers
mikroBASIC
making it simple. . .
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
Cf_Fat_Get_Swap_File
Prototype Returns
sub function Cf_Fat_Get_Swap_File(dim sectors_cnt as longint)as longint
No. of start sector for the newly created swap file, if swap file was created; otherwise, the function returns zero. It accepts as sectors_cnt argument the number of consecutive sectors that user wants the swap file to have. During its execution, the function searches for the available consecutive sectors, their number being specified by the sectors_cnt argument. If there is such space on the media, the swap file named MIKROSWP. SYS is created, and that space is designated (in FAT tables) to it. The attributes of this file are: system, archive and hidden, in order to distinct it from other files. If a file named MIKROSWP. SYS already exists on the media, this function deletes it upon creating the new one. The purpose of the swap file is to make reading and writing to CF media as fast as possible, without potentially damaging the FAT system. Swap file can be considered as a "window" on the media where user can freely write/read the data, in any way (s)he wants to. Its main purpose in mikroBasic library is to be used for fast data acquisition; when the time-critical acquisition has finished, the data can be re-written into a "normal" file, and formatted in the most suitable way.
Description
Requires Example
Ports must be initialized for FAT operations with CF. See Cf_Fat_Init.
'-------------- Tries to create a swap file, whose size will be 'at least 100 sectors. of start sector over USART sub procedure C_Create_Swap_File size = Cf_Fat_Get_Swap_File(100) if (size) then Usart_Write($AA) Usart_Write(Lo(size)) Usart_Write(Hi(size)) Usart_Write(Higher(size)) Usart_Write(Highest(size)) Usart_Write($AA) end if end sub
page
mikroElektronika: Development tools - Books - Compilers
139
mikroBASIC
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
making it simple. . .
Library Examples
The following example writes 512 bytes at sector no. 590, and then reads the data and prints on PORTC for a visual check.
program Cf_example dim i as word dim temp, k as longint main: TRISC = 0 Cf_Init(PORTB, PORTD) do nop loop until Cf_Detect = true Delay_ms(500) Cf_Write_Init(590, 1) address 590 for i = 0 to 511 Cf_Write_Byte(i + 11) next i PORTC = $FF Delay_ms(1000) Cf_Read_Init(590, 1) for i = 0 to 511 PORTC = Cf_Read_Byte Delay_ms(1000) next i end. ' Wait until CF card is inserted
' PORTC is output ' Initialize ports
' Initialize write at sector ' of 1 sector (512 bytes) ' Write 512 bytes to sector (590)
' Initialize write at sector address 590 ' of 1 sector (512 bytes) ' Read 512 bytes from sector (590) ' Read byte and display on PORTC
page
140
mikroElektronika: Development tools - Books - Compilers
mikroBASIC
making it simple. . .
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
HW Connection
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
40 39 38 37 36 35 34 33
PIC18F452
VCC
11 12 13 14 15 8 MhZ VCC GND OSC1 OSC2 RC0
RD7 RD6 RD5 RD4
30 29 28 27
19 20
RD0 RD1
RD3 RD2
22 21
VCC
RD7 RD6 RD5 RD4 RD3 RD2 RD1 RD0
50 49 25
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0
24 48 23 47 22 46 21 45 20 44 19 43 18 42 17 41 16 40 15 39 14 38 13 37 12 36 11 35 10 34 9 33 8 32 7 31 6 30 5 29 4 28 3 27 2 26 1
Compact Flash Card
R25 10K
VCC
page
mikroElektronika: Development tools - Books - Compilers
141
mikroBASIC
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
making it simple. . .
EEPROM Library
EEPROM data memory is available with a number of PICmicros. mikroBasic includes library for comfortable work with EEPROM.
Library Routines
Eeprom_Read Eeprom_Write
Eeprom_Read
Prototype Returns Description
sub function EEprom_read(dim Address as word) as byte
Returns byte from specified address. Parameter address is of byte type, which means it can address only 1024 locations. For PIC18 micros with more EEPROM data locations, it is programmer's responsibility to set EEADRH register appropriately. Ensure minimum 20ms delay between successive use of routines Eeprom_Write and Eeprom_Read. Although PIC will write the correct value, Eeprom_Read might return an undefined result.
Requires
Example
take = Eeprom_Read($3F)
page
142
mikroElektronika: Development tools - Books - Compilers
mikroBASIC
making it simple. . .
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
Eeprom_Write
Prototype Description
sub procedure EEprom_write(dim Address as word, dim Data as byte)
Writes data to specified address. Parameter address is of byte type, which means it can address only 1024 locations. For PIC18 micros with more EEPROM data locations, it is programmer's responsibility to set EEADRH register appropriately. [. . . ] GLCD needs to be initialized, see Spi_T6963C_Config.
Spi_T6963C_negBit(b)
page
mikroElektronika: Development tools - Books - Compilers
333
mikroBASIC
mikroBASIC - BASIC Compiler for Microchip PIC microcontrollers
making it simple. . .
Spi_T6963C_displayGrPanel
Prototype Description Requires Example
sub procedure Spi_T6963C_displayGrPanel(dim n as word)
Display graphic panel number n. GLCD needs to be initialized, see Spi_T6963C_Config.
Spi_T6963C_displayGrPanel(n)
Spi_T6963C_displayTxtPanel
Prototype Description Requires Example
sub procedure Spi_T6963C_displayTxtPanel(dim n as word)
Display text panel number n. GLCD needs to be initialized, see Spi_T6963C_Config.
Spi_T6963C_displayTxtPanel(n)
Spi_T6963C_setGrPanel
Prototype Description Requires Example
sub procedure Spi_T6963C_setGrPanel(dim n as word)
Compute graphic start address for panel number n. GLCD needs to be initialized, see Spi_T6963C_Config.
Spi_T6963C_setGrPanel(n)
Spi_T6963C_setTxtPanel
Prototype Description Requires Example
sub procedure Spi_T6963C_setTxtPanel(dim n as word)
Compute text start address for panel number n. [. . . ]