MainBrain Firmware Reference

System is Powered On
/MCLR is held in reset until 250mS after Vdd reaches 3.0V
System Loads Configuration
Microcontroller loads the configuration bits located in Boot Flash memory
System Waits for POSC
System waits until POSC is stable
SystemSetup()
Digital I/O, LED port, SOSC, analog inputs disabled, PBCLKx setup, pre-cache, multi vector interrupt mode, USB_init()
LED_Port(0x1)
PMP_init()
Parallel Master Port configuration
LED_Port(0x2)
REN70V05_Init()
SRAM configuration
LED_Port(0x3)
SRAM Test
Not yet implemented
Flash_Init()
Configures Flash memory and reads the manufacturer ID (MID) and the device ID (DID).
LED_Port(0x5)
TMR4_init()
Timer 4 module configuration
LED_Port(0x7)
I2C_init()
I2C module configuration
LED_Port(0x8)
TMR1_init()
Timer 1 module configuration
LED_Port(0x9)
ADC_init()
ADC module configuration
LED_Port(0xa)
Display_init()
Display configuration
LED_Port(0xb)
SetDisplayBrightness()
Gets the display brightness value from Falsh memory and if it is blank sets it to 5 (50%)
Display_CLRSCN(0xffff)
Clears the screen and paints the background color passed by the function
Display_DISPON()
Turns on the display
TMR6_init()
Timer 6 module configuration
LED_Port(0xc)
TMR3_init()
Timer 3 module configuration
Beep()
Beeps the buzzer to indicate configuration has completed
__builtin_enable_interrupts()
Enable the interrupts
LED_Port(0x0)
ShowSplashScreen(0)
Loads the splash screen and passes an option
Set Home Screen
Sets the initial display graphics
Build Peripherals List
Creat a list of the peripheral boards connected to the system
while(1)
Main program loop

Main Program Loop

The main program loop continuously outputs the heartbeat, checks for messages, directives, and screen touches and loads the initial graphics screen. External functions can request a new graphics screen and the main Function will change the current screen global so that another function can load the newly requested graphics. A message or directive is requested by an external program and subsequently processed by the main loop. This is done by branching to a function that handles the message box requested by the message or, for a directive, initiates an I/O cycle. Touch events are handled by the touch interrupt service which determines how many touches occured and the X,Y location on the screen and passes the information to global variables that can be processed by other external functions. The heartbeat toggles TP1 each time the main loop starts a new cycle. This indicates the main loop is indeed looping and at what frequency. This can be a valuable debugging tool.

Heartbeat out on TP1
The heartbeat indicates the main program loop is running
Process Pending Message
Messages create a message box that contain a text message describing a system event
Process Pending Directive
Directives control the peripherals by initiating an I/O cycle
Load Screen
Loads the currently specified graphics
Process Touch
Processes touch events