Reviews & Opinions
Independent and trusted. Read before buy Mikroelektronika Mikrobasic!

Mikroelektronika Mikrobasic


Bookmark
Mikroelektronika Mikrobasic

Bookmark and Share

 

Mikroelektronika MikrobasicAbout Mikroelektronika Mikrobasic
Here you can find all about Mikroelektronika Mikrobasic like manual and other informations. For example: review.

Mikroelektronika Mikrobasic manual (user guide) is ready to download for free.

On the bottom of page users can write a review. If you own a Mikroelektronika Mikrobasic please write about it to help other people.
[ Report abuse or wrong photo | Share your Mikroelektronika Mikrobasic photo ]

 

 

Manual

Preview of first few manual pages (at low quality). Check before download. Click to enlarge.
Manual - 1 page  Manual - 2 page  Manual - 3 page 

Download (English)
Mikroelektronika Mikrobasic - Version 5.0, size: 1.8 MB

 

Mikroelektronika Mikrobasic

 

 

Video review

2 Two Wire LCD Interface

 

User reviews and opinions

<== Click here to post a new opinion, comment, review, etc.

No opinions have been provided. Be the first and add a new opinion/review.

 

Documents

doc0

MikroElektronika: Development tools - Books - Compilers

Watch Window

Code Explorer

Code Editor

Error Window Code Assistant Breakpoints Window
mikroBasic allows you to quickly develop and deploy complex applications: - Write your BASIC source code using the highly advanced Code Editor - Use the included mikroBasic libraries to dramatically speed up the development: data acquisition, memory, displays, conversions, communications - Monitor your program structure, variables, and functions in the Code Explorer. Generate commented, human-readable assembly, and standard HEX compatible with all programmers. - Inspect program flow and debug executable logic with the integrated Debugger. Get detailed reports and graphs on code statistics, assembly listing, calling tree - We have provided plenty of examples for you to expand, develop, and use as building bricks in your projects.

CODE EDITOR

The Code Editor is advanced text editor fashioned to satisfy the needs of professionals. General code editing is same as working with any standard text-editor, including familiar Copy, Paste, and Undo actions, common for Windows environment. Advanced Editor features include: - Adjustable Syntax Highlighting - Code Assistant - Parameter Assistant - Code Templates - Auto Correct for common typos - Bookmarks and Goto Line You can customize these options from Editor Settings dialog. To access the settings, click Tools > Options from the drop-down menu, or click the Tools icon.

Tools Icon.

Code Assistant [CTRL+SPACE] If you type first few letter of a word and then press CTRL+SPACE, all valid identifiers matching the letters you typed will be prompted to you in a floating panel (see the image). Now you can keep typing to narrow the choice, or you can select one from the list using the keyboard arrows and Enter.
Parameter Assistant [CTRL+SHIFT+SPACE] The Parameter Assistant will be automatically invoked when you open a parenthesis "(" or press CTRL+SHIFT+SPACE. If name of valid function or procedure precedes the parenthesis, then the expected parameters will be prompted to you in a floating panel. As you type the actual parameter, next expected parameter will become bold.
Code Template [CTR+J] You can insert the Code Template by typing the name of the template (for instance, whileb), then press CTRL+J, and Editor will automatically generate code. Or you can click button from Code toolbar and select template from the list. You can add your own templates to the list. Just select Tools > Options from the drop-down menu, or click the Tools Icon from the Settings Toolbar, and then select the Auto Complete Tab. Here you can enter the appropriate keyword, description, and code of your template.
Auto Correct The Auto Correct feature corrects some common typing mistakes. To access the list of recognized typos, select Tools > Options from the drop-down menu, or click Tools Icon from Settings Toolbar, and then select Auto Correct Tab. You can also add your own preferences to the list.

Double click the message line in the Error Window to highlight the line where the error was encountered. Consult the Error Messages for more information about errors recognized by the compiler.

STATISTICS

After successful compilation, you can review statistics of your code. Select Project > View Statistics from the drop-down menu, or click the Statistics icon. There are six tab windows: Memory Usage Window Provides overview of RAM and ROM memory usage in form of histogram.

Statistics Icon.

Procedures (Graph) Window Displays functions in form of histogram, according to their memory allotment.
Procedures (Locations) Window Displays how functions are distributd in microcontrollers memory.
Procedures (Details) Window Displays complete call tree, along with details for each procedure and function:
size, start and end address, calling frequency, return type, etc.
RAM Window Summarizes all GPR and SFR registers and their addresses. Also displays symbolic names of variables and their addresses.
ROM Window Lists op-codes and their addresses in form of a human readable hex code.

INTEGRATED TOOLS

USART Terminal mikroBasic includes the USART (Universal Synchronous Asynchronous Receiver Transmitter) communication terminal for RS232 communication. You can launch it from the drop-down menu Tools > Terminal or by clicking the Terminal icon.
ASCII Chart ASCII Chart is a handy tool, particularly useful when working with LCD display. You can launch it from the drop-down menu Tools > ASCII chart.
7 Segment Display Decoder The 7seg Display Decoder is a convenient visual panel which returns decimal/hex value for any viable combination you would like to display on 7seg. Click on the parts of 7 segment image to the left to get the desired value in the edit boxes. You can launch it from the drop-down menu Tools > 7 Segment Display.
EEPROM Editor EEPROM Editor allows you to easily manage EEPROM of PIC microcontroller.

mikroBootloader

mikroBootloader can be used only with PICmicros that support flash write. 1. Load the PIC with the appropriate hex file using the conventional programming techniques (e.g. for PIC16F877A use p16f877a.hex). 2. Start mikroBootloader from the drop-down menu Tools > Bootoader. 3. Click on Setup Port and select the COM port that will be used. Make sure that BAUD is set to 9600 Kpbs. 4. Click on Open File and select the HEX file you would like to upload. 5. Since the bootcode in the PIC only gives the computer 4-5 sec to connect, you should reset the PIC and then click on the Connect button within 4-5 seconds. 6. The last line in then history window should now read Connected. 7. To start the upload, just click on the Start Bootloader button. 8. Your program will written to the PIC flash. Bootloader will report an errors that may occur. 9. Reset your PIC and start to execute. The boot code gives the computer 5 seconds to get connected to it. If not, it starts running the existing user code. If there is a new user code to be downloaded, the boot code receives and writes the data into program memory. The more common features a bootloader may have are listed below: - Code at the Reset location. - Code elsewhere in a small area of memory. - Checks to see if the user wants new user code to be loaded. - Starts execution of the user code if no new user code is to be loaded. - Receives new user code via a communication channel if code is to be loaded. - Programs the new user code into memory. Integrating User Code and Boot Code The boot code almost always uses the Reset location and some additional program memory. It is a simple piece of code that does not need to use interrupts; therefore, the user code can use the normal interrupt vector at 0x0004. The boot code must avoid using the interrupt vector, so it should have a program branch in the address range 0x0000 to 0x0003. The boot code must be programmed into memory using conventional programming techniques, and the configuration bits must be programmed at this time. The boot code is unable to access the configuration bits, since they are not mapped into the program memory space.

Select Case Statement Use the select case statement to pass control to a specific program branch, based on a certain condition. The select case statement consists of a selector expression (a condition) and a list of possible values. Syntax of select case statement is:
select case selector case value_1 statements_1. case value_n statements_n [case else default_statements] end select
The selector is an expression which should evaluate as integral value. The values can be literals, constants, or expressions. The statements can be any statements. The else clause is optional. First, the selector expression (condition) is evaluated. The select case statement then compares it against all the available values. If the match is found, the statements following the match evaluate, and select case statement terminates. In case there are multiple matches, the first matching statement will be executed. If none of the values matches the selector, then the default_statements in the else clause (if there is one) are executed. Here is a simple example of select case statement:
select case operator case "*" res = n1 * n2 case "/" res = n1 / n2 case "+" res = n1 + n2 case "-" res = n1 - n2 case else res = 0 Inc(cnt) end select
Also, you can group values together for a match. Simply separate the items by commas:
select case reg case 0 opmode = 0 case 1,2,3,4 opmode = 1 case 5,6,7 opmode = 2 end select
Nested Case Statements Note that select case statements can be nested values are then assigned to the innermost enclosing select case statement.
Iteration Statements (Loops)
Iteration statements let you loop a set of statements. There are three forms of iteration statements in mikroBasic: for, while, and do. You can use the statements break and continue to control the flow of a loop statement. The break terminates the statement in which it occurs, while continue begins executing the next iteration of the sequence.
For Statement The for statement implements an iterative loop and requires you to specify the number of iterations. Syntax of for statement is:
for counter = initial_value to final_value [step step_value] statements next counter
The counter is a variable which increases by step_value with each iteration of the loop. Parameter step_value is an optional integral value, and defaults to 1 if omitted. Before the first iteration, counter is set to the initial_value and will increment until it reaches (or exceeds) the final_value. The initial_value and final_value should be expressions compatible with the counter; statements can be any statements that do not change the value of counter. Note that parameter step_value may be negative, allowing you to create a countdown. Here is an example of calculating scalar product of two vectors, a and b, of length n, using for statement:

CANSPISetOperationMode

sub procedure CANSPISetOperationMode(dim mode, wait_flag as byte)
Sets CAN to requested mode, i.e. copies mode to CANSTAT. Parameter mode needs to be one of CAN_OP_MODE constants (see CAN constants, page 141). Parameter wait_flag needs to be either 0 or 0xFF: If set to 0xFF, this is a blocking call the function wont return until the requested mode is set. If 0, this is a nonblocking call. It does not verify if CAN module is switched to requested mode or not. Caller must use function CANSPIGetOperationMode to verify correct operation mode before performing mode specific operation.
CANSPI functions are supported by any PIC MCU that has SPI interface on PORTC. Also, CS pin of MCP2510 or MCP2515 must be connected to RC0.
CANSPISetOperationMode(CAN_MODE_CONFIG, $FF)

CANSPIGetOperationMode

sub function CANSPIGetOperationMode as byte
Current opmode. Function returns current operational mode of CAN module.
if (CANSPIGetOperationMode = CAN_MODE_CONFIG) then.

CANSPIInitialize

sub procedure CANSPIInitialize(dim SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_CONFIG_FLAGS as byte, dim byref RstPort as byte, dim RstPin as byte, dim byref CSPort as byte, dim CSPin as byte)
Initializes CANSPI. All pending transmissions are aborted. Sets all mask registers to 0 to allow all messages. Filter registers are set according to flag value:
if ((CAN_CONFIG_FLAGS and CAN_CONFIG_VALID_XTD_MSG) = 0) then ' Set all filters to XTD_MSG else if ((config and CONFIG_VALID_STD_MSG) = 0) then ' Set all filters to STD_MSG else ' Set half the filters to STD, and the rest to XTD_MSG
SJW as defined in 18XXX8 datasheet (14) BRP as defined in 18XXX8 datasheet (164) PHSEG1 as defined in 18XXX8 datasheet (18) PHSEG2 as defined in 18XXX8 datasheet (18) PROPSEG as defined in 18XXX8 datasheet (18) CAN_CONFIG_FLAGS is formed from predefined constants (see CAN constants, page

99). Requires

SPI_Init must be called before initializing CANSPI.
CANSPI must be in Config mode; otherwise the function will be ignored. Example
init = CAN_CONFIG_SAMPLE_THRICE and CAN_CONFIG_PHSEG2_PRG_ON and CAN_CONFIG_STD_MSG and CAN_CONFIG_DBL_BUFFER_ON and CAN_CONFIG_VALID_XTD_MSG and CAN_CONFIG_LINE_FILTER_OFF. ' initialize external CAN module CANSPIInitialize(1,1,3,3,1,aa, PORTC, 2, PORTC, 0)

CANSPISetBaudRate

sub procedure CANSPISetBaudRate(dim SJW, BRP, PHSEG1, PHSEG2, PROPSEG, CAN_CONFIG_FLAGS as byte)
Sets CANSPI baud rate. Due to complexity of CANSPI protocol, you cannot simply force a bps value. Instead, use this function when CANSPI is in Config mode. Refer to datasheet for details. Parameters:
CANSPI must be in Config mode; otherwise the function will be ignored.
init = CAN_CONFIG_SAMPLE_THRICE CAN_CONFIG_PHSEG2_PRG_ON CAN_CONFIG_STD_MSG CAN_CONFIG_DBL_BUFFER_ON CAN_CONFIG_VALID_XTD_MSG CAN_CONFIG_LINE_FILTER_OFF. CANSPISetBaudRate(1, 1, 3, 3, 1, and and and and and

CANSPISetMask

sub procedure CANSPISetMask(dim CAN_MASK as byte, dim value as longint, dim CAN_CONFIG_FLAGS as byte)
' Set all mask bits to 1, i.e. all filtered bits are relevant: CANSPISetMask(CAN_MASK_B1, -1, CAN_CONFIG_XTD_MSG) ' Note that -1 is just a cheaper way to write $FFFFFFFF. ' Complement will do the trick and fill it up with ones

CANSPISetFilter

sub procedure CANSPISetFilter(dim CAN_FILTER as byte, dim val as longint, dim CAN_CONFIG_FLAGS as byte)
' Set id of filter B1_F1 to 3: CANSPISetFilter(CAN_FILTER_B1_F1, 3, CAN_CONFIG_XTD_MSG)

CANSPIRead

sub function CANSPIRead(dim byref id as longint, dim byref data as byte[8], dim byref DataLen, CAN_RX_MSG_FLAGS as byte) as byte
CANSPI must be in mode in which receiving is possible.
rcv = CANSPIRead(id, data, len, rx)

CANSPIWrite

sub function CANSPIWrite(dim id as longint, dim byref data as byte[8], dim datalen, CAN_TX_MSG_FLAGS as byte) as byte
Returns zero if message cannot be queued (buffer full). If at least one empty transmit buffer is found, function sends message on queue for transmission. If buffer is full, function returns 0. Parameters: id is CANSPI message identifier. Only 11 or 29 bits may be used depending on message type (standard or extended); data is array of bytes up to 8 bytes in length; datalen is data length from 18; CAN_TX_MSG_FLAGS is value formed from constants (see CAN constants).

' Set IP address 192.168.20.25 Eth_Set_Ip_Address(192, 168, 20, 25)

Eth_Set_Inport

sub function Eth_Inport(dim address as byte) as byte
One byte from the specified address. Retrieves a byte from the specified address of the Ethernet card chip. The card (NIC) must be properly initialized. See Eth_Init.
udp_length = udp_length or Eth_Inport(NIC_DATA)

Eth_Scan_For_Event

sub function Eth_Scan_For_Event(dim byref next_ptr as byte) as word
Type of the ethernet packet received. Two types are distinguished: ARP (MAC-IP address data request) and IP (Internet Protocol). Retrieves senders MAC (hardware) address and type of the packet received. The function argument is an (internal) pointer to the next data packet in RTL8019s buffer, and is of no particular importance to the end user. The card (NIC) must be properly initialized. See Eth_Init. Also, the function must be called in a proper sequence, i.e. right after the card init and IP address/UDP port init.
while TRUE event_type = Eth_Scan_For_Event(next_ptr) select case event_type case ARP Arp_Event() ' Some event handler case IP Ip_Event() ' Some event handler end select Eth_Outport(CR, $22) Eth_Outport(BNDRY, next_ptr) wend

' Scan for event

Eth_Get_Ip_Hdr_Len
sub function Eth_Get_Ip_Hdr_Len as byte
Header length of the received IP packet. Function returns header length of the received IP packet. Before other data based upon the IP protocol (TCP, UDP, ICMP) can be analyzed, the sub-protocol data must be properly loaded from the received IP packet. The card (NIC) must be properly initialized. See Eth_Init. The function must be called in a proper sequence, i.e. immediately after determining that the packet received is the IP packet.
' Receive IP Header opt_len = Eth_Get_Ip_Hdr_Len() - 20

Eth_Load_Ip_Packet

Prototype Description Requires
sub procedure Eth_Load_Ip_Packet
Loads various IP packet data into PICs Ethernet variables. The card (NIC) must be properly initialized. See Eth_Init. Also, a proper sequence of calls must be obeyed (see the Ip_Event function in the supplied Ethernet example).

Eth_Load_Ip_Packet()

Eth_Get_Hdr_Chksum
sub procedure Eth_Get_Hdr_Chksum
Loads and returns the header checksum of the received IP packet. The card (NIC) must be properly initialized. See Eth_Init. Also, a proper sequence of calls must be obeyed (see the Ip_Event function in the supplied Ethernet example).

Returns Description

Nothing. Initialize ENC controller. This function is splited into 2 parts to help linker when coming short of memory.
resetPort - pointer to reset pin port resetBit - reset bit number on resetPort CSport - pointer to CS pin port CSbit - CS bit number on CSport mac - pointer to array of 6 char with MAC address ip - pointer to array of 4 char with IP address fullDuplex - either SPI_Ethernet_HALFDUPLEX for half duplex or SPI_Ethernet_FULLDUPLEX for full duplex
SPI_Init must be called before initializing SPI Ethernet. SPI_Ethernet_Init(PORTC, 0, PORTC, 1, myMacAddr, myIpAddr, SPI_Ethernet_FULLDUPLEX)

SPI_Ethernet_doPacket

sub procedure SPI_Ethernet_doPacket
Nothing. Process one incoming packet if available. SPI_Ethernet_init must have been called before using this function. This function must be called as often as possible by user.

SPI_Ethernet_putByte

sub procedure ENC28J60_putByte(dim v as byte)

Nothing.

v - value to store
Store one byte to current EWRPT ENC location. Requires Example SPI_Ethernet_init must have been called before calling this function.
SPI_Ethernet_putByte(0xa0)

SPI_Ethernet_getByte

dim function SPI_Ethernet_getByte as byte
Value of byte @ addr. Get next byte from current ERDPT ENC location. SPI_Ethernet_init must have been called before calling this function.

b = SPI_Ethernet_getByte

SPI_Ethernet_UserTCP
sub function SPI_Ethernet_UserTCP(dim byref remoteHost as byte[4], dim remotePort, localPort, reqLength as word) as word
Returns the length in bytes of the HTTP reply, or 0 if nothing to transmit. This function is called by the library. The user accesses to the HTTP request by successive calls to SPI_Ethernet_getByte the user puts data in the transmit buffer by successive calls to SPI_Ethernet_putByte the function must return the length in bytes of the HTTP reply, or 0 if nothing to transmit. If you don't need to reply to HTTP requests, just define this function with a return(0) as single statement. SPI_Ethernet_init must have been called before calling this function.

SPI_Ethernet_UserUDP

sub function SPI_Ethernet_UserUDP(dim byref remoteHost as byte[4], remotePort, destPort, reqLength as word) as word

Lcd8_Out(2, 3, "i") ' Print "i" at line 2, char 3

Lcd8_Chr_Cp

sub procedure Lcd8_Chr_Cp(dim character as byte)
Prints character on LCD at current cursor position. Both variables and literals can be passed as character. Ports with LCD must be initialized. See Lcd8_Config or Lcd8_Init.
Lcd8_Chr_Cp("e") ' Print "e" at current cursor position

Lcd8_Cmd

sub procedure Lcd8_Cmd(dim command as byte)
Sends command to LCD. You can pass one of the predefined constants to the function. The complete list of available commands is on the page 140. Ports with LCD must be initialized. See Lcd8_Config or Lcd8_Init.
Lcd8_Cmd(LCD_CLEAR) ' Clear LCD display
program Lcd8_default_test dim text as char[20] main: TRISB = 0 TRISC = 0 Lcd8_Init(PORTB, PORTC) Lcd8_Cmd(LCD_CURSOR_OFF) text = "mikroElektronika" Lcd8_Out(1, 1, text) end.
PORTB is output PORTC is output Initialize LCD at PORTB and PORTC Turn off cursor

' Print text at LCD

MCLR RA0 RA1 RA2 RA3 RA4 RA5 RE0 RE1 RE2 VDD VSS OSC1 OSC2
RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 VDD VSS RD7 RD6 RD5 RD4

D7 D6 D5 D4 E R/W RS

RC1 RC2 RC3
RC6 RC5 RC4 RD0 RD1 RD3 RD2

GLCD Library

mikroBasic provides a library for drawing and writing on Graphic LCD. These routines work with commonly used GLCD 128x64, and work only with the PIC18 family.

Basic routines:

Glcd_Init Glcd_Set_Side Glcd_Set_Page Glcd_Set_X Glcd_Read_Data Glcd_Write_Data

Advanced routines:

Glcd_Fill Glcd_Dot Glcd_Line Glcd_V_Line Glcd_H_Line Glcd_Rectangle Glcd_Box Glcd_Circle Glcd_Set_Font Glcd_Write_Char Glcd_Write_Text Glcd_Image

Glcd_Init

sub procedure Glcd_Init(dim byref ctrlport as byte, dim cs1, cs2, rs, rw, rst, en as byte, dim byref dataport as byte)
Initializes GLCD at lower byte of data_port with pin settings you specify. Parameters cs1, cs2, rs, rw, rst, and en can be pins of any available port. This procedure needs to be called befored using other routines of GLCD library.
Glcd_Init(PORTB, 2, 0, 3, 5, 7, 1, PORTC)

T6963C_rectangle(20, 20, 219, 107, T6963C_WHITE)

T6963C_box

sub procedure T6963C_box(dim x0, y0, x1, y1 as integer, dim pcolor as byte)
This routine sets current graphic work panel. It draws a solid box in the rectangle (x0, y0)-(x1, y1). pcolor = T6963C_[WHITE[BLACK]. Ports must be initialized. See T6963C_init.
T6963C_box(0, 119, 239, 127, T6963C_WHITE)

T6963C_circle

sub procedure T6963C_circle(dim x, y as integer, dim r as longint, dim pcolor as word)
This routine sets current graphic work panel. It draws a circle, center is (x, y), diameter is r. pcolor = T6963C_[WHITE[BLACK] Ports must be initialized. See T6963C_init.
T6963C_circle(120, 64, 110, T6963C_WHITE)

T6963C_image

sub procedure T6963C_image(const pic as ^byte)
This routine sets current graphic work panel : It fills graphic area with picture pointer by MCU. MCU must fit the display geometry. For example : for a 240x128 display, MCU must be an array of (240/8)*128 = 3840 bytes. Ports must be initialized. See T6963C_init.

T6963C_image(my_image)

T6963C_sprite
sub procedure T6963C_sprite(dim px, py as byte, const pic as ^byte, dim sx, sy as byte)
This routine sets current graphic work panel. It fills graphic rectangle area (px, py)-(px + sx, py + sy) witch picture pointed by MCU. Sx and sy must be the size of the picture. MCU must be an array of sx*sy bytes. Ports must be initialized. See T6963C_init.
T6963C_sprite(76, 4, einstein, 88, 119) ' draw a sprite

T6963C_set_cursor

sub procedure T6963C_set_cursor(dim x, y as byte)
This routine sets cursor row x line y. Ports must be initialized. See T6963C_init.
T6963C_set_cursor(cposx, cposy)

T6963C_clearBit

sub procedure T6963C_clearBit(dim b as byte)
Clear control bit. Ports must be initialized. See T6963C_init.

T6963C_clearBit(b)

T6963C_setBit
sub procedure T6963C_setBit(dim b as byte)
Set control bit. Ports must be initialized. See T6963C_init.

T6963C_setBit(b)

T6963C_negBit
sub procedure T6963C_negBit(b as byte)
Neg control bit. Ports must be initialized. See T6963C_init.

T6963C_negBit(b)

T6963C_displayGrPanel
sub procedure T6963C_displayGrPanel(dim n as word)
Display graphic panel number n. GLCD needs to be initialized, see T6963C_init.

T6963C_displayGrPanel(n)

T6963C_displayTxtPanel
sub procedure T6963C_displayTxtPanel(dim n as word)
Display text panel number n. GLCD needs to be initialized, see T6963C_init.
T6963C_displayTxtPanel(n)

T6963C_setGrPanel

sub procedure T6963C_setGrPanel(dim n as word)
Compute graphic start address for panel number n. Ports must be initialized. See T6963C_init.

T6963C_setGrPanel(n)

T6963C_setTxtPanel
sub procedure T6963C_setTxtPanel(dim n as word)
Compute text start address for panel number n. Ports must be initialized. See T6963C_init.

T6963C_setTxtPanel(n)

T6963C_panelFill
sub procedure T6963C_panelFill(dim v as word)
Fill full #n panel with v bitmap (0 to clear). Ports must be initialized. See T6963C_init.

T6963C_panelFill(v)

T6963C_grFill
sub procedure T6963C_grFill(dim v as word)
Fill graphic #n panel with v bitmap (0 to clear). Ports must be initialized. See T6963C_init.

T6963C_grFill(v)

T6963C_txtFill
sub procedure T6963C_txtFill(dim v as word)
Fill text #n panel with char v + 32 (0 to clear). Ports must be initialized. See T6963C_init.

T6963C_txtFill(v)

T6963C_cursor_height
sub procedure T6963C_cursor_height(dim n as word)
Set cursor size. Ports must be initialized. See T6963C_init.

T6963C_cursor_height(n)

T6963C_graphics
sub procedure T6963C_graphics(dim n as word)
Set graphics on/off. GLCD needs to be initialized, see T6963C_init.

T6963C_graphics(1)

T6963C_text
sub procedure T6963C_text(dim n as word)
Set text on/off. GLCD needs to be initialized, see T6963C_init.

T6963C_text(1)

T6963C_cursor
sub procedure T6963C_cursor(dim n as word)
Set cursor on/off. Ports must be initialized. See T6963C_init.

T6963C_cursor(1)

T6963C_cursor_blink
sub procedure T6963C_cursor_blink(dim n as word)
Set cursor blink on/off. Ports must be initialized. See T6963C_init.

T6963C_cursor_blink(0)

T6963C_Init_240x128
sub procedure T6963C_Init_240x128
Initialize T6963C based GLCD (240x128 pixels) with default settings for mE GLCD's.

T6963C_Init_240x64

sub procedure T6963C_Init_240x64
Initialize T6963C based GLCD (240x64 pixels) with default settings for mE GLCD's.
The following drawing demo tests advanced routines of T6963C GLCD library.
program T6963C include "__Lib_T6963c" include "bitmap" include "bitmap2" dim panel as byte ' current panel i as word ' general purpose register curs as byte ' cursor visibility cposx, cposy as word ' cursor x-y position main: TRISC = 0xFFFF TRISB = 0x0000 PORTD = 0 TRISD = 0 T6963C_init(240, 128, 8, PORTD, PORTB, 3, 2, 1, 5) ' ' ' {* * enable both graphics and text display at the same time *} T6963C_graphics(1) T6963C_text(1)

Mmc_Fat_Reset

sub procedure Mmc_Fat_Reset(dim byref size as longint)
Procedure resets the file pointer (moves it to the start of the file) of the assigned file, so that the file can be read. Parameter size stores the size of the assigned file, in bytes. The file must be assigned, see Mmc_Fat_Assign.

Mmc_Fat_Reset(size)

Mmc_Fat_Rewrite
sub procedure Mmc_Fat_Rewrite
Procedure resets the file pointer and clears the assigned file, so that new data can be written into the file. The file must be assigned, see Mmc_Fat_Assign.

Mmc_Fat_Append

sub procedure Mmc_Fat_Append
The procedure moves the file pointer to the end of the assigned file, so that data can be appended to the file. The file must be assigned, see Mmc_Fat_Assign.

Mmc_Fat_Read

sub procedure Mmc_Fat_Read(dim byref data as byte)
Procedure reads the byte at which the file pointer points to and stores data into parameter data. The file pointer automatically increments with each call of Mmc_Fat_Read. The file must be assigned, see Mmc_Fat_Assign. Also, file pointer must be initialized; see Mmc_Fat_Reset.

Mmc_Fat_Read(mydata)

Mmc_Fat_Write
sub procedure Mmc_Fat_Write(dim byref fdata as char[512], dim datalen as word)
Procedure writes a chunk of bytes (fdata) to the currently assigned file, at the position of the file pointer. The file must be assigned, see Mmc_Fat_Assign. Also, file pointer must be initialized; see Mmc_Fat_Append or Mmc_Fat_Rewrite.
Mmc_Fat_Write(txt,255) Mmc_Fat_Write(Hello world,255)

Mmc_Fat_Set_File_Date

sub procedure Mmc_Fat_Set_File_Date(dim year as word, dim month, day, hours, min, sec as byte)
Writes system timestamp to a file. Use this routine before each writing to file; otherwise, the file will be appended an unknown timestamp. File pointer must be initialized; see Mmc_Fat_Assign and Mmc_Fat_Reset.
' April 1st 2005, 18:07:00 Mmc_Fat_Set_File_Date(2005, 4, 1, 18, 7, 0)

Mmc_Fat_Get_File_Date

sub procedure Mmc_Fat_Get_File_Date(dim byref year as word, dim byref month, day, hours, min, sec as byte)

Hid_Write(@wr, len)

Hid_Disable
sub procedure Hid_Disable
Disables USB HID communication.
The following example continually sends sequence of numbers 0.255 to the PC via Universal Serial Bus.
program hid_test dim k as byte dim userRD_buffer as byte[64] dim userWR_buffer as byte[64] sub procedure interrupt asm CALL _Hid_InterruptProc nop end asm end sub sub procedure Init_Main ' Disable all interrupts ' Disable GIE, PEIE, TMR0IE, INT0IE,RBIE INTCON = 0 INTCON2 = $F5 INTCON3 = $C0 ' Disable Priority Levels on interrupts RCON.IPEN = 0 PIE1 = 0 PIE2 = 0 PIR1 = 0 PIR2 = 0 ' Configure all ports with analog function as digital ADCON1 = ADCON1 or $0F TRISA TRISB TRISC TRISD TRISE LATA LATB LATC LATD LATE = = = = = = = = = = 0 $FF $FF $07
'. continued ' Clear user RAM ' Banks [00. 07] ( 8 x 256 = 2048 Bytes ) asm LFSR FSR0, $000 MOVLW $08 CLRF POSTINC0, 0 CPFSEQ FSR0H, 0 BRA $ - 2 end asm ' Timer 0 T0CON = $07; TMR0H = (65536 TMR0L = (65536 INTCON.T0IE = T0CON.TMR0ON = end sub
- 156) >> 8 - 156) and $FF 1 ' Enable T0IE 1
'** Main Program ** main: Init_Main() Hid_Enable(@userRD_buffer, @userWR_buffer) do for k = 0 to 255 ' Prepare send buffer userWR_buffer[0] = k ' Send the number via USB Hid_Write(@userWR_buffer, 1) next k loop until FALSE Hid_Disable end.

MCLR RA0 RA1 RA2

RB7 RB6 RB5 RB4

PIC18F4550

RA3 RA4 RA5 RE0 RE1
RB3 RB2 RB1 RB0 VDD VSS RD7 RD6 RD5 RD4 RC7 RC6 RC5 RC4 RD3 RD2
RE2 VDD VSS OSC1 OSC2 RC0 RC1 RC2 Vusb

VCC VCC DD+

Util Library
Util library contains miscellaneous routines useful for project development.

Button

sub function Button(dim byref port as byte, dim pin, time, active_state as byte) as byte
Returns 0 or 255. Function eliminates the influence of contact flickering upon pressing a button (debouncing). Parameter port specifies the location of the button; parameter pin is the pin number on designated port and goes from 0.7; parameter time is a debounce period in milliseconds; parameter active_state can be either 0 or 1, and it determines if the button is active upon logical zero or logical one.
Example reads RB0, to which the button is connected; on transition from 1 to 0 (release of button), PORTD is inverted:
while true if Button(PORTB, 0, 1, 1) then oldstate = 255 end if if oldstate and Button(PORTB, 0, 1, 0) then PORTD = not(PORTD) oldstate = 0 end if wend

Conversions Library

mikroBasic Conversions Library provides routines for converting numerals to strings, and routines for BCD/decimal conversions. You can get text representation of numerical value by passing it to one of the following routines:
ByteToStr ShortToStr WordToStr WordToStrWithZeros IntToStr LongintToStr FloatToStr

Following functions convert decimal values to BCD (Binary Coded Decimal) and vice versa:
Bcd2Dec Dec2Bcd Bcd2Dec16 Dec2Bcd16

ByteToStr

sub procedure ByteToStr(dim number as byte, dim byref output as string[3])
Procedure creates an output string out of a small unsigned number (numerical value less than $100). Output string has fixed width of 3 characters; remaining positions on the left (if any) are filled with blanks.
dim t as word dim txt as string[3] '. t = 24 ByteToStr(t, txt) ' txt is " 24" (one blank here)

ShortToStr

sub procedure ShortToStr(dim number as short, dim byref output as string[4])
Procedure creates an output string out of a small signed number (numerical value less than $100). Output string has fixed width of 4 characters; remaining positions on the left (if any) are filled with blanks.
dim t as short dim txt as string[4]; '. t = -24 ShortToStr(t, txt) ' txt is " -24" (one blank here)

WordToStr

sub procedure WordToStr(dim number as word, dim byref output as string[5])
Procedure creates an output string out of an unsigned number (numerical value of word type). Output string has fixed width of 5 characters; remaining positions on the left (if any) are filled with blanks.
dim t as word dim txt as string[5] '. t = 437 WordToStr(t, txt) ' txt is "
437" (two blanks here)

WordToStrWithZeros

sub procedure WordToStrWithZeros(dim number as word, dim byref output as string[5])
Procedure creates an output string out of an unsigned number (numerical value of word type). Output string has fixed width of 5 characters; remaining positions on the left (if any) are filled with zeros. The output string should have the exact length as specified in the procedure prototype (5 characters).

IntToStr

sub procedure IntToStr(dim number as integer, dim byref output as string[6])
Procedure creates an output string out of a signed number (numerical value of integer type). Output string has fixed width of 6 characters; remaining positions on the left (if any) are filled with blanks.

doc1

GENERAL PROVISIONS

This statement may only be modified in writing signed by you and an authorised officer of mikroElektronika Associates. If any provision of this statement is found void or unenforceable, the remainder will remain valid and enforceable according to its terms. If any remedy provided is determined to have failed for its essential purpose, all limitations of liability and exclusions of damages set forth in the Limited Warranty shall remain in effect. This statement gives you specific legal rights; you may have others, which vary, from country to country. mikroElektronika Associates reserves all rights not specifically granted in this statement. mikroElektronika Visegradska 1A, 11000 Belgrade, Europe. Phone: + 830 Fax: +831 Web: www.mikroe.com E-mail: office@mikroe.com

TECHNICAL SUPPORT

In case you encounter any problem, you are welcome to our support forums at www.mikroe.com/forum/. Here, you may also find helpful information, hardware tips, and practical code snippets. Your comments and suggestions on future development of the mikroBasic PRO for PIC are always appreciated feel free to drop a note or two on our Wishlist. In our Knowledge Base www.mikroe.com/en/kb/ you can find the answers to Frequently Asked Questions and solutions to known problems. If you can not find the solution to your problem in Knowledge Base then report it to Support Desk www.mikroe.com/en/support/. In this way, we can record and track down bugs more efficiently, which is in our mutual interest. We respond to every bug report and question in a suitable manner, ever improving our technical support

How to Register

The latest version of the mikroBasic PRO for PIC is always available for downloading from our website. It is a fully functional software libraries, examples, and comprehensive help included. The only limitation of the free version is that it cannot generate hex output over 2 KB. Although it might sound restrictive, this margin allows you to develop practical, working applications with no thinking of demo limit. If you intend to develop really complex projects in the mikroBasic PRO for PIC, then you should consider the possibility of purchasing the license key.

Who Gets the License Key

Buyers of the mikroBasic PRO for PIC are entitled to the license key. After you have completed the payment procedure, you have an option of registering your mikroBasic PRO. In this way you can generate hex output without any limitations.

How to Get License Key

After you have completed the payment procedure, start the program. Select Help How to Register from the drop-down menu or click the How To Register Icon Fill out the registration form (figure below), select your distributor, and click the Send button.

Metacharacters - Predefined classes

\w \W \d \D \s \S

an alphanumeric character (including "_") a nonalphanumeric a numeric character a non-numeric any space (same as [\t\n\r\f]) a non space
You may use \w, \d and \s within custom character classes.

Example:

routi\de - matches strings like 'routi1e', 'routi6e' and so on, but not 'routine', 'routime' and so on.
Metacharacters - Word boundaries
A word boundary ("\b") is a spot between two characters that has a "\w" on one side of it and a "\W" on the other side of it (in either order), counting the imaginary characters off the beginning and end of the string as matching a "\W".
\b - match a word boundary) \B - match a non-(word boundary)
Metacharacters - Iterators
Any item of a regular expression may be followed by another type of metacharacters - iterators. Using this metacharacters,you can specify number of occurences of previous character, metacharacter or subexpression.
* - zero or more ("greedy"), similar to {0,} + - one or more ("greedy"), similar to {1,} ? - zero or one ("greedy"), similar to {0,1} {n} - exactly n times ("greedy") {n,} - at least n times ("greedy") {n,m} - at least n but not more than m times ("greedy") *? - zero or more ("non-greedy"), similar to {0,}? +? - one or more ("non-greedy"), similar to {1,}? ?? - zero or one ("non-greedy"), similar to {0,1}? {n}? - exactly n times ("non-greedy") {n,}? - at least n times ("non-greedy") {n,m}? - at least n but not more than m times ("non-greedy")
So, digits in curly brackets of the form, {n,m}, specify the minimum number of times to match the item n and the maximum m. The form {n} is equivalent to {n,n} and matches exactly n times. The form {n,} matches n or more times. There is no limit to the size of n or m, but large numbers will chew up more memory and slow down execution. If a curly bracket occurs in any other context, it is treated as a regular character.
count.*r - matches strings like 'counter', 'countelkjdflkj9r' and

'countr'

ANALOG DEBUG TEST

There are some predefined project level defines. See predefined project level defines Related topics: Project Manager, Project Settings

SOURCE FILES

Source files containing Basic code should have the extension.mbas. The list of source files relevant to the application is stored in project file with extension.mbpav, along with other project information. You can compile source files only if they are part of the project.
Managing Source Files Creating new source file
To create a new source file, do the following: 1. Select File New Unit from the drop-down menu, or press Ctrl+N, or click the New File Icon from the File Toolbar. from 2. A new tab will be opened. This is a new source file. Select File Save from the drop-down menu, or press Ctrl+S, or click the Save File Icon the File Toolbar and name it as you want. If you use the New Project Wizard, an empty source file, named after the project with extension.mbas, will be created automatically. The mikroBasic PRO for PIC does not require you to have a source file named the same as the project, its just a matter of convenience.

Opening an existing file

1. Select File Open from the drop-down menu, or press Ctrl+O, or click the Open File Icon from the File Toolbar. In Open Dialog browse to the loca tion of the file that you want to open, select it and click the Open button. 2. The selected file is displayed in its own tab. If the selected file is already open, its current Editor tab will become active.

Printing an open file

1. Make sure that the window containing the file that you want to print is the active window. 2. Select File Print from the drop-down menu, or press Ctrl+P. 3. In the Print Preview Window, set a desired layout of the document and click the OK button. The file will be printed on the selected printer.

Saving file

1. Make sure that the window containing the file that you want to save is the active window. 2. Select File Save from the drop-down menu, or press Ctrl+S, or click the Save File Icon from the File Toolbar.
Saving file under a different name
1. Make sure that the window containing the file that you want to save is the active window. 2. Select File Save As from the drop-down menu. The New File Name dialog will be displayed. 3. In the dialog, browse to the folder where you want to save the file. 4. In the File Name field, modify the name of the file you want to save. 5. Click the Save button.

Closing file

1. Make sure that the tab containing the file that you want to close is the active tab. 2. Select File Close from the drop-down menu, or right click the tab of the file that you want to close and select Close option from the context menu. 3. If the file has been changed since it was last saved, you will be prompted to save your changes. Related topics:File Menu, File Toolbar, Project Manager, Project Settings,

CLEAN PROJECT FOLDER

This menu gives you option to choose which files from your current project you want to delete. Files marked in bold can be easily recreated by building a project. Other files should be marked for deletion only with a great care, because IDE cannot recover them.
Related topics: Customizing Projects

Environment COMPILATION

When you have created the project and written the source code, it's time to compile it. Select Project Build from the drop-down menu, or click the Build Icon from the Project Toolbar. If more more than one project is open you can compile all open projects by selecting Project Build All from the drop-down menu, or click the Build All Icon from the Project Toolbar.
Progress bar will appear to inform you about the status of compiling. If there are some errors, you will be notified in the Error Window. If no errors are encountered, the mikroBasic PRO for PIC will generate output files.

Output Files

Upon successful compilation, the mikroBasic PRO for PIC will generate output files in the project folder (folder which contains the project file.mbpav). Output files are summarized in the table below: Format Intel HEX Binary List File Assembler File Description Intel style hex records. Use this file to program PIC MCU mikro Compiled Library. Binary distribution of application that can be included in other projects. Overview of PIC memory allotment: instruction addresses, registers, routines and labels. Human readable assembly with symbolic names, extracted from the List File. File Type

.hex.mcl.lst.asm

Assembly View
After compiling the program in the mikroBasic PRO for PIC, you can click the View Assembly icon or select Project View Assembly from the drop-down menu to review the generated assembly code (.asm file) in a new tab window. Assembly is human-readable with symbolic names. Related topics:Project Menu, Project Toolbar, Error Window, Project Manager, Project Settings

Program Memory Break

Program Memory Break is used to set the Advanced Breakpoint to the specific address in program memory. Because of PIC pipelining mechanism program execution may stop one or two instructions after the address entered in the Address field. Value entered in the Address field must be in hex format. Note: Program Memory Break can use the Passcount option. The program execution will stop when the specified program address is reached for the N-th time, where N is the number entered in the Passcount field. When some Advanced Breakpoint stops the program execution, passcount counters for all Advanced Breakpoints will be cleared.

File Register Break

File Register Break can be used to stop the code execution when read/write access to the specific data memory location occurs. If Read Access is selected, the File Register Equal option can be used to set the matching value. The program execution will be stopped when the value read from the specified data memory location is equal to the number written in the Value field. Values entered in the Address and Value fields must be in hex format. Note: File Register Break can also use the Passcount option in the same way as Program Memory Break.
Emulator Features Event Breakpoints
Break on Stack Overflow/Underflow : not implemented. Break on Watchdog Timer : not implemented. Break on SLEEP : break on SLEEP instruction. SLEEP instruction will not be executed. If you choose to continue the mikroICD debugging [F6] then the program execution will start from the first instruction following the SLEEP instruction.

Stopwatch

Stopwatch uses Breakpoint#2 and Breakpoint#3 as a Start and Stop conditions. To use the Stopwatch define these two Breakpoints and check the Enable Stopwatch checkbox. Stopwatch options: Halt on Start Condition (Breakpoint#2): when checked, the program exe cution will stop on Breakpoint#2. Otherwise, Breakpoint#2 will be used only to start the Stopwatch. Halt on Stop Condition (Breakpoint#3): when checked, the program exe cution will stop on Breakpoint#3. Otherwise, Breakpoint#3 will be used only to stop the Stopwatch. Reset Stopwatch on Run : when checked, the Stopwatch will be cleared before continuing program execution and the next counting will start from zero. Otherwise, the next counting will start from the previous Stopwatch value. MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD

sub function Ethernet_putString(dim ptr as ^byte) as word
Number of bytes written into Ethernet controller's RAM. This is MAC module routine. It stores whole string (excluding null termination) into Ethernet controller's RAM starting from current Ethernet controller's write pointer (EWRPT) location.

Description Parameters:

ptr: string to be written into Ethernet controller's RAM.
dim buffer as string[16]. buffer = "mikroElektronika". Ethernet_putString(buffer) ' put a RAM string into ethernet buffer

Ethernet_putConstString

sub function Ethernet_putConstString(const ptr as ^byte) as word
Number of bytes written into Ethernet controller's RAM. This is MAC module routine. It stores whole const string (excluding null termination) into Ethernet controller's RAM starting from current Ethernet controller's write pointer (EWRPT) location.
ptr: const string to be written into Ethernet controller's RAM.
const buffer as string[16]. buffer = "mikroElektronika". Ethernet_putConstString(buffer) ' put a const string into ethernet buffer

Ethernet_getByte

Prototype Returns Description Requires
sub function Ethernet_getByte() as byte
Byte read from Ethernet controller's RAM. This is MAC module routine. It fetches a byte from address pointed to by current Ethernet controller's read pointer (ERDPT). Ethernet module has to be initialized. See Ethernet_Init.
dim buffer as byte. buffer = Ethernet_getByte() buffer
' read a byte from ethernet

Ethernet_getBytes

sub procedure Ethernet_getBytes(dim ptr as ^byte, dim addr as word, dim n as byte)
Nothing. This is MAC module routine. It fetches equested number of bytes from Ethernet controller's RAM starting from given address. If value of 0xFFFF is passed as the address parameter, the reading will start from current Ethernet controller's read pointer (ERDPT) location.
ptr: buffer for storing bytes read from Ethernet controller's RAM. addr: Ethernet controller's RAM start address. Valid values: 0.8192. n: number of bytes to be read.
dim buffer as byte[16]. Ethernet_getBytes(buffer, 0x100, 16) ' read 16 bytes, starting from address 0x100

Ethernet_UserTCP

sub function Ethernet_UserTCP(dim byref remoteHost as byte[4], dim remotePort, localPort, reqLength as word) as word
0 - there should not be a reply to the request. Length of TCP/HTTP reply data field - otherwise. This is TCP module routine. It is internally called by the library. The user accesses to the TCP/HTTP request by using some of the Ethernet_get routines. The user puts data in the transmit buffer by using some of the Ethernet_put routines. The function must return the length in bytes of the TCP/HTTP reply, or 0 if there is nothing to transmit. If there is no need to reply to the TCP/HTTP requests, just define this function with return(0) as a single statement.

ip: IP address to be resolved. tmax: time in seconds to wait for an reply.
Note: The Ethernet services are not stopped while this routine waits for ARP reply. The incoming packets will be processed normaly during this time. Requires Ethernet module has to be initialized. See Ethernet_Init.
dim IpAddr as byte[4] ' IP address. IpAddr[0] = 192 IpAddr[0] = 168 IpAddr[0] = 1 IpAddr[0] = 1. Ethernet_arpResolve(IpAddr, 5) ' get MAC address behind the above IP address, wait 5 secs for the response

Ethernet_sendUDP

sub function Ethernet_sendUDP(dim byref destIP as byte[4], dim sourcePort, destPort as word, dim pkt as ^byte, dim pktLen as word) as byte
1 - UDP packet was sent successfully. 0 - otherwise. This is UDP module routine. It sends an UDP packet on the network. Parameters:
destIP: remote host IP address. sourcePort: local UDP source port number. destPort: destination UDP port number. pkt: packet to transmit. pktLen: length in bytes of packet to transmit.
dim IpAddr as byte[4] ' remote IP address. IpAddr[0] = 192 IpAddr[0] = 168 IpAddr[0] = 1 IpAddr[0] = 1. Ethernet_sendUDP(IpAddr, 10001, 10001, "Hello", 5) ' send Hello message to the above IP address, from UDP port 10001 to UDP port 10001

Ethernet_dnsResolve

sub function Ethernet_dnsResolve(dim byref host as byte[4], dim tmax as byte) as word
pointer to the location holding the IP address - the requested host name was resolved. 0 - otherwise. This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply. If the requested host name was resolved, it's IP address is stored in library global variable and a pointer containing this address is returned by the routine. UDP port 53 is used as DNS port. Parameters:
host: host name to be resolved. tmax: time in seconds to wait for an reply.
Note: The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will be processed normaly during this time. Note: User should always copy the IP address from the RAM location returned by this routine into it's own resolved host IP address buffer. These locations should not be altered by the user in any case! Requires Ethernet module has to be initialized. See Ethernet_Init.
dim remoteHostIpAddr as byte[4] ' user host IP address buffer. ' SNTP server: ' Zurich, Switzerland: Integrated Systems Lab, Swiss Fed. Inst. of Technology ' 129.132.2.21: swisstime.ethz.ch ' Service Area: Switzerland and Europe memcpy(remoteHostIpAddr, Ethernet_dnsResolve("swisstime.ethz.ch", 5), 4)

Ethernet_initDHCP

sub function Ethernet_initDHCP(dim tmax as byte) as byte

'forPIC18 sub procedure FLASH_Erase_64(dim address as dword) sub procedure FLASH_Erase_1024(dim address as dword)
Erases memory block starting from a given address. For P16 familly is impleDescription mented only for those MCU's whose flash memory does not support erase-andwrite operations (refer to datasheet for details). Requires Example

FLASH_Erase_64($0D00)

Nothing. Erase 64 byte memory memory block, starting from address $0D00:

FLASH_Erase_Write

' for PIC18 sub procedure FLASH_Erase_Write_64(dim address as dword, dim byref data as byte[64]) sub procedure FLASH_Erase_Write_1024(dim address as dword, dim byref data as byte[1024])
Description Erase then write memory block starting from a given address. Requires Nothing.
dim toWrite as byte[64]. main:. ' initialize array: for i = 0 to 63 toWrite[i] = i next i. ' erase block of memory at address 0x0D00 then write contents of the array to the address 0x0D00: FLASH_Erase_Write_64(0x0D00, toWrite). end.
This is a simple demonstration how to use to PIC16 internal flash memory to store data. The data is being written starting from the given location; then, the same locations are read and the data is displayed on PORTB and PORTC.
program Flash_Write dim counter as byte addr, data_ as word dataAR as word[4][4] ANSEL = 0 ANSELH = 0 C1ON_bit = 0 C2ON_bit = 0 PORTB = 0 TRISB = 0 PORTC = 0 TRISC = 0 Delay_ms(500) ' ' ' ' ' ' Configure AN pins as digital ' Disable comparators ' ' ' ' Initial PORTB value Set PORTB as output Initial PORTC value Set PORTC as output
All block writes to program memory are done as 16-word erase by eight-word write operations. The write operation is edge-aligned and cannot occur across boundaries. Therefore it is recommended to perform flash writes in 16-word chunks. ' That is why lower 4 bits of start address [3:0] must be zero. ' Since FLASH_Write routine performs writes in 4-word chunks, ' we need to call it 4 times in a row. dataAR[0][0]= dataAR[0][1]= dataAR[0][2]= dataAR[0][3]= dataAR[1][0]= dataAR[1][1]= dataAR[1][2]= dataAR[1][3]= dataAR[2][0]= dataAR[2][1]= dataAR[2][2]= dataAR[2][3]= dataAR[3][0]= dataAR[3][1]= dataAR[3][2]= dataAR[3][3]= 0x3FAA+0 0x3FAA+1 0x3FAA+2 0x3FAA+3 0x3FAA+4 0x3FAA+5 0x3FAA+6 0x3FAA+7 0x3FAA+8 0x3FAA+9 0x3FAA+10 0x3FAA+11 0x3FAA+12 0x3FAA+13 0x3FAA+14 0x3FAA+15
addr = 0x0430 ' starting Flash address, valid for P16F88 for counter = 0 to 3 ' write some data to Flash Delay_ms(100) FLASH_Write(addr+counter*4, dataAR[counter]) next counter Delay_ms(500) addr = 0x0430 for counter = 0 to 15 data_ = FLASH_Read(addr) Inc(addr) Delay_us(10) PORTB = data_ PORTC = word(data_ >> 8) Delay_ms(500) next counter end.

' 2 seconds delay sub function
' Initialize Glcd ' Clear Glcd

' Draw image

' Clear Glcd ' Draw box
Glcd_Rectangle(5,5,84,35,1) Glcd_Line(0, 0, 127, 63, 1) Delay2S() counter = 5 ' Draw rectangle ' Draw line
while (counter <= 59) ' Draw horizontal and vertical lines Delay_ms(250) Glcd_V_Line(2, 54, counter, 1) Glcd_H_Line(2, 120, counter, 1) Counter = counter + 5 wend Delay2S() Glcd_Fill(0x00) Glcd_Set_Font(@Character8x7, 8, 7, 32) "Character8x7" Glcd_Write_Text("mikroE", 1, 7, 2) for counter = 1 to 10 Glcd_Circle(63,32, 3*counter, 1) next counter Delay2S() Glcd_Box(10,20, 70,63, 2) Delay2S() Glcd_Fill(0xFF) Glcd_Set_Font(@Character8x7, 8, 7, 32) someText = "8x7 Font" Glcd_Write_Text(someText, 5, 0, 2) delay2S() Glcd_Set_Font(@System3x6, 3, 5, 32) someText = "3X5 CAPITALS ONLY" Glcd_Write_Text(someText, 60, 2, 2) delay2S() Glcd_Set_Font(@font5x7, 5, 7, 32) someText = "5x7 Font" Glcd_Write_Text(someText, 5, 4, 2) delay2S() ' Clear Glcd ' Choose font ' Write string ' Draw circles

' Draw box}

' Fill Glcd ' Change font ' Write string
' Change font ' Write string
Glcd_Set_Font(@FontSystem5x7_v2, 5, 7, 32) ' Change font someText = "5x7 Font (v2)" Glcd_Write_Text(someText, 5, 6, 2) ' Write string delay2S()
Glcd_Set_Font(@FontSystem5x7_v2, 5, 7, 32) ' Change font someText = "5x7 Font (v2)" Glcd_Write_Text(someText, 5, 6, 2) ' Write string delay2S() wend end.

Glcd HW connection

IC LIBRARY
I2C full master MSSP module is available with a number of PIC MCU models. mikroBasic PRO for PIC provides library which supports the master I2C mode. Note: Some MCUs have multiple I2C modules. In order to use the desired I2C library routine, simply change the number 1 in the prototype with the appropriate module number, i.e.

I2C1_Init(100000)

I2C1_Init I2C1_Start I2C1_Repeated_Start I2C1_Is_Idle I2C1_Rd I2C1_Wr I2C1_Stop
I2C1_Init Prototype Returns
sub procedure I2C1_Init(const clock as longint)
Nothing. Initializes I2C with desired clock (refer to device data sheet for correct values in respect with Fosc). Needs to be called before using other functions of I2C Library. You dont need to configure ports manually for using the module; library will take care of the initialization. Library requires MSSP module on PORTB or PORTC.
Note: Calculation of the I2C clock value is carried out by the compiler, as it would produce a relatively large code if performed on the libary level. Therefore, compiler needs to know the value of the parameter in the compile time. That is why this parameter needs to be a constant, and not a variable.

' Set Port Expander's PORTA and PORTB pull-up resistors Expander_Set_PullUpsPortAB(0, 0xFFFF)
The example demonstrates how to communicate with Port Expander MCP23S17. Note that Port Expander pins A2 A1 A0 are connected to GND so Port Expander Hardware Address is 0.
program PortExpander ' Port Expander module connections dim SPExpanderRST as sbit at RC0_bit SPExpanderCS as sbit at RC1_bit SPExpanderRST_Direction as sbit at TRISC0_bit SPExpanderCS_Direction as sbit at TRISC1_bit ' End Port Expander module connections dim counter as byte' = 0 main: counter = 0 ANSEL = 0 ANSELH = 0 TRISB = 0 PORTB = 0
' Configure AN pins as digital I/O ' Set PORTB as output
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV4, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH) ' Initialize Port Expander Expander_Init(0) Expander_Set_DirectionPortA(0, 0x00) ' Set Expander's PORTA to be output Expander_Set_DirectionPortB(0,0xFF) ' Set Expander's PORTB to be input Expander_Set_PullUpsPortB(0,0xFF) ' Set pull-ups to all of the Expander's PORTB pins while TRUE Expander_Write_PortA(0, counter) Inc(counter) PORTB = Expander_Read_PortB(0) write it to LEDs Delay_ms(100) wend end. ' Endless loop ' Write i to expander's PORTA ' Read expander's PORTB and
Port Expander HW connection

Libraries PS/2 LIBRARY

The mikroBasic PRO for PIC provides a library for communication with the common PS/2 keyboard. Note: The library does not utilize interrupts for data retrieval, and requires the oscillator clock to be at least 6MHz. Note: The pins to which a PS/2 keyboard is attached should be connected to the pull-up resistors. Note: Although PS/2 is a two-way communication bus, this library does not provide MCU-to-keyboard communication; e.g. pressing the Caps Lock key will not turn on the Caps Lock LED.
External dependencies of PS/2 Library
The following variables must be defined in all projects using PS/2 Library:
dim PS2_Data as sbit sfr external dim PS2_Clock as sbit sfr external dim PS2_Data_Direction as sbit sfr external
PS/2 Data line. PS/2 Clock line.
dim PS2_Data as sbit at RC0_bit dim PS2_Clock as sbit at RC1_bit
Direction of the PS/2 Data dim PS2_Data_Direction as pin.

sbit at TRISC0_bit

Direction of the PS/2
dim PS2_Clock_Direction Clock pin. as sbit sfr external
dim PS2_Clock_Direction as sbit at TRISC1_bit

Ps2_Config Ps2_Key_Read

Ps2_Config
sub procedure Ps2_Config()
Description Initializes the MCU for work with the PS/2 keyboard. Global variables :
PS2_Data: Data signal line PS2_Clock: Clock signal line in PS2_Data_Direction: Direction of the Data pin PS2_Clock_Direction: Direction of the Clock pin

9, bits 8 & 9 does not exist but does not matter bitMask = getRequest[6] - "0" ' convert ASCII to integer bitMask = 1 << bitMask ' create bit mask PORTD = PORTD xor bitMask ' toggle PORTD with xor operator end if end if end if if(result = 0) then ' what do to by default result = SPI_Ethernet_putConstString(@httpHeader) ' HTTP header result = result + SPI_Ethernet_putConstString(@httpMimeTypeHTML) ' with HTML MIME type result = result + SPI_Ethernet_putConstString(@indexPage) ' HTML page first part result = result + SPI_Ethernet_putConstString(@indexPage2) ' HTML page second part end if ' return to the library with the number of bytes to transmit end sub ' * ' * this code shows how to use the Spi_Ethernet mini library : ' * the board will reply to ARP & ICMP echo requests ' * the board will reply to UDP requests on any port : ' * returns the request in upper char with a header made of remote host IP & port number ' * the board will reply to HTTP requests on port 80, GET method with pathnames : ' * / will return the HTML main page ' * /s will return board status as text string ' * /t0. /t7 will toggle RD0 to RD7 bit and return HTML main page ' * all other requests return also HTML main page ' * sub function Spi_Ethernet_UserUDP(dim byref remoteHost as byte[4], dim remotePort, destPort, reqLength as word) as word result = 0 ' reply is made of the remote host IP address in human readable format byteToStr(remoteHost[0], dyna) ' first IP address byte dyna[3] = "." byteToStr(remoteHost[1], tmp) ' second dyna[4] = tmp[0] dyna[5] = tmp[1] dyna[6] = tmp[2] dyna[7] = ". "
byteToStr(remoteHost[2], tmp) dyna[8] = tmp[0] dyna[9] = tmp[1] dyna[10] = tmp[2] dyna[11] = "." byteToStr(remoteHost[3], tmp) dyna[12] = tmp[0] dyna[13] = tmp[1] dyna[14] = tmp[2] dyna[15] = ":" ' then remote host port number WordToStr(remotePort, tmp) dyna[16] = tmp[0] dyna[17] = tmp[1] dyna[18] = tmp[2] dyna[19] = tmp[3] dyna[20] = tmp[4] dyna[21] = "[" WordToStr(destPort, tmp) dyna[22] = tmp[0] dyna[23] = tmp[1] dyna[24] = tmp[2] dyna[25] = tmp[3] dyna[26] = tmp[4] dyna[27] = "]" dyna[28] = 0 ' the total length of the request is the length of the dynamic string plus the text of the request result = 28 + reqLength ' puts the dynamic string into the transmit buffer SPI_Ethernet_putBytes(@dyna, 28) ' then puts the request string converted into upper char into the transmit buffer while(reqLength <> 0) SPI_Ethernet_putByte(SPI_Ethernet_getByte()) reqLength = reqLength - 1 wend ' back to the library with the length of the UDP reply end sub main: ANSEL = 0x0C ' AN2 and AN3 convertors will be used PORTA = 0 TRISA = 0xff ' set PORTA as input for ADC ANSELH = 0 ' Configure other AN pins as digital I/O ' second

_LCD_MOVE_CURSOR_RIGHT Move cursor right without changing display data RAM _LCD_TURN_ON _LCD_TURN_OFF _LCD_SHIFT_LEFT _LCD_SHIFT_RIGHT
Turn Lcd display on Turn Lcd display off Shift display left without changing display data RAM Shift display right without changing display data RAM
This example demonstrates how to communicate Lcd via the SPI module, using serial to parallel convertor MCP23S17.
program SPI_Lcd dim text as char[17] ' Port Expander module connections dim SPExpanderRST as sbit at RC0_bit SPExpanderCS as sbit at RC1_bit SPExpanderRST_Direction as sbit at TRISC0_bit SPExpanderCS_Direction as sbit at TRISC1_bit ' End Port Expander module connections main: text = "mikroElektronika" SPI1_Init() PortExpander SPI_Lcd_Config(0) face SPI_Lcd_Cmd(_LCD_CLEAR) SPI_Lcd_Cmd(_LCD_CURSOR_OFF) SPI_Lcd_Out(1,6, "mikroE") 6th column SPI_Lcd_Chr_CP("!") SPI_Lcd_Out(2,1, text) column end.
' Initialize SPI module used with ' Initialize Lcd over SPI inter' Clear display ' Turn cursor off ' Print text to Lcd, 1st row, ' Append "!" ' Print text to Lcd, 2nd row, 1st

SPI LCD HW connection

Libraries SPI LCD8 (8-BIT INTERFACE) LIBRARY
The mikroBasic PRO for PIC provides a library for communication with Lcd (with HD44780 compliant controllers) in 8-bit mode via SPI interface. For creating a custom set of Lcd characters use Lcd Custom Character Tool. Note: Library uses the SPI module for communication. The user must initialize the SPI module before using the SPI Lcd Library. For MCUs with two SPI modules it is possible to initialize both of them and then switch by using the SPI_Set_Active() routine. Note: This Library is designed to work with mikroElektronika's Serial Lcd/GLcd Adapter Board pinout, see schematic at the bottom of this page for details.
The implementation of SPI Lcd Library routines is based on Port Expander Library routines. External dependencies are the same as Port Expander Library external dependencies.

' enable text displaying T6963C_Text(1)

T6963C_Cursor

sub procedure T6963C_Cursor(dim n as byte)
n: on/off parameter. Valid values: 0 (set cursor off) and 1 (set cursor on).
' set cursor on T6963C_Cursor(1)

T6963C_Cursor_Blink

sub procedure T6963C_Cursor_Blink(dim n as byte)
n: on/off parameter. Valid values: 0 (disable cursor blinking) and 1 (enable cursor blinking).
' enable cursor blinking T6963C_Cursor_Blink(1)
The following drawing demo tests advanced routines of the T6963C Glcd library. Hardware configurations in this example are made for the T6963C 240x128 display, EasyPIC5 board and PIC16F887.
program T6963C_240x128 include __Lib_T6963C_Consts include einstein_bmp include mikroe_bmp ' T6963C module connections dim T6963C_dataPort as byte at PORTD

' DATA port

dim T6963C_ctrlwr as sbit at RC2_bit ' WR write signal dim T6963C_ctrlrd as sbit at RC1_bit ' RD read signal ' CD command/data signal dim T6963C_ctrlcd as sbit at RC0_bit dim T6963C_ctrlrst as sbit at RC4_bit ' RST reset signal dim T6963C_ctrlwr_Direction as sbit at TRISC2_bit ' WR write signal direction dim T6963C_ctrlrd_Direction as sbit at TRISC1_bit ' RD read signal direction dim T6963C_ctrlcd_Direction as sbit at TRISC0_bit ' CD command/data signal direction dim T6963C_ctrlrst_Direction as sbit at TRISC4_bit ' RST reset signal direction ' Signals not used by library, they are set in main sub function dim T6963C_ctrlce as sbit at RC3_bit ' CE signal dim T6963C_ctrlfs as sbit at RC6_bit ' FS signal dim T6963C_ctrlmd as sbit at RC5_bit ' MD signal dim T6963C_ctrlce_Direction as sbit at TRISC3_bit ' CE signal direction dim T6963C_ctrlfs_Direction as sbit at TRISC6_bit ' FS signal direction dim T6963C_ctrlmd_Direction as sbit at TRISC5_bit ' MD signal direction ' End T6963C module connections dim panel as byte ' i as word ' curs as byte ' cposx, cposy as word ' txtcols as byte ' txt, txt1 as string[29] current panel general purpose register cursor visibility cursor x-y position number of text coloms

 

Tags

Pagepro 9100 WD-8030W 2500C PRO CLP-133 91 LV Ii-platinum R-26ST M1877N Fishfinder Headphones DB458RMC MDX-CA580 Pc 900 1810334 VT570 Armani HDC-HS9 FLS802 SIN 010 Intelliguard 770 Urc-3300N Bandit 650S EOS-1D DSC-WX5 Bladesystem 23PF4321-01 Review W-865R RDR-DC100 Racer GT Siege BXR 300C EMS2320X Seccoprof Presenter Dect 211 AZ291MA CMK7026RE SGH-X560 TX-950 WJ-HD316 9239A-2 3YM30 Bizhub C35 Nikkor 5-device S2450 PV-DV103D ED-301 Hotpoint-ariston WD64 RQ 742 Triton 200 Legend GT-CC-01 DVD-R119 Yzea 650 MP100 WOM Inspiron 9100 707II RM1300 WM-EX600 SU-V505 CS700 Hardware Cyborg EVO Wide Zoom Dtxpress P45DE3 7700G KDL-L32rx2 H3800 I XL RD-HA3 MCR-308 PPM1012 DB456MC DCR-DVD505 Micro-ondes Alcatel-lucent 4059 VA521 Black Easyshare C360 NV7802U LP-9200C LV800 285 W Infocus IN82 170MP Ericsson T18S Zoom 90 A12M A15W 1210XI Catalogue 2007 Cmdae 5 1 Kiel CD35 1 0 P-334WH 41512 SUP 015 Sportster

 

manuel d'instructions, Guide de l'utilisateur | Manual de instrucciones, Instrucciones de uso | Bedienungsanleitung, Bedienungsanleitung | Manual de Instruções, guia do usuário | инструкция | návod na použitie, Užívateľská príručka, návod k použití | bruksanvisningen | instrukcja, podręcznik użytkownika | kullanım kılavuzu, Kullanım | kézikönyv, használati útmutató | manuale di istruzioni, istruzioni d'uso | handleiding, gebruikershandleiding

 

Sitemap

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101