Home
Downloads
Licenses Contact

Basic Compiler Simulation Test Examples

During the software development, sometimes there is a need to write a basic test example that is very suitable for the simulation.
Having in mind that it could be very useful for some users to get new ideas how OshonSoft software packages could be used, some of those basic test examples will be published on this page.
Feel free to share some of your basic programs that simulate nicely to be published here...



atmega328p uart custom fifo buffer implementation

(screenshot)

- set simulation rate to ultimate
- change uart transmit/receive time to 50us
- start the simulation; wait around 100ms real time for the lcd to be initialized
- use send char command to send chars: a, b, c, d
- use send byte (dec) command to send byte value 10 and trigger buffer reading
- set simulation rate to extremely fast for easier uart interface events tracking
- use send char command to send chars: a, b, c, d, e, f; another buffer reading will be triggered

basic program:
'fifo buffer declarations
Dim fifobuff(10) As Byte
Const fifoN = 10
Dim fifobuff_readpoint As Byte
Dim fifobuff_writepoint As Byte
Dim fifobuff_size As Byte
Dim fifobuff_lastchar As Byte
fifobuff_readpoint = 0
fifobuff_writepoint = 0
fifobuff_size = 0
fifobuff_lastchar = 0

'device initialization
UART_Init 19200

'enable uart receive interrupt
Enable URXC
Enable

'user program
Dim mymessage As String
Lcdinit LcdCurBlink

'there are two variables available to check the buffer state
'fifobuff_size - number of bytes waiting to be read
'fifobuff_lastchar - ascii code of the last received char in the buffer
loop:

If fifobuff_size > 5 Then
        Lcdcmdout LcdLine1Clear
        Lcdout fifobuff_readstring()
Endif

If fifobuff_lastchar = 10 Then 'line feed (ascii 10) char received
        mymessage = fifobuff_readstring()
        mymessage = LeftStr(mymessage, Len(mymessage) - 1) 'remove line feed char
        fifobuff_lastchar = 0
        Lcdcmdout LcdLine1Clear
        Lcdout mymessage
Endif

Goto loop
End

On Interrupt URXC
        Dim arg1 As Byte
        UART_Get arg1
        Call fifobuff_write(arg1)
Resume

Proc fifobuff_write(ByVal arg1 As Byte)
        If fifobuff_size = fifoN Then
                Exit 'code for the buffer overrun
        Endif
        fifobuff(fifobuff_writepoint) = arg1
        fifobuff_lastchar = arg1
        fifobuff_writepoint = fifobuff_writepoint + 1
        If fifobuff_writepoint = fifoN Then fifobuff_writepoint = 0
        fifobuff_size = fifobuff_size + 1
End Proc

Function fifobuff_read() As Byte
        If fifobuff_size = 0 Then
                Exit 'code for the buffer underrun
        Endif
        fifobuff_read = fifobuff(fifobuff_readpoint)
        fifobuff_readpoint = fifobuff_readpoint + 1
        If fifobuff_readpoint = fifoN Then fifobuff_readpoint = 0
        fifobuff_size = fifobuff_size - 1
End Function

Function fifobuff_readstring() As String
        fifobuff_readstring = ""
        While fifobuff_size > 0
                fifobuff_readstring = fifobuff_readstring + Chr(fifobuff_read())
        Wend
End Function



pic18 uart custom fifo buffer implementation

(screenshot)

- set simulation rate to ultimate
- change uart transmit/receive time to 50us

basic program:
'fifo buffer declarations
Dim fifobuff(10) As Byte
Const fifoN = 10
Dim fifobuff_readpoint As Byte
Dim fifobuff_writepoint As Byte
Dim fifobuff_size As Byte
Dim fifobuff_lastchar As Byte
fifobuff_readpoint = 0
fifobuff_writepoint = 0
fifobuff_size = 0
fifobuff_lastchar = 0

'device initialization
All_Digital
UART1_Init 19200

'enable uart receive interrupt
Enable High
PIE1.RC1IE = 1

'user program
Dim mymessage As String
Lcdinit LcdCurBlink

'there are two variables available to check the buffer state
'fifobuff_size - number of bytes waiting to be read
'fifobuff_lastchar - ascii code of the last received char in the buffer
loop:

If fifobuff_size > 5 Then
        Lcdcmdout LcdLine1Clear
        Lcdout fifobuff_readstring()
Endif

If fifobuff_lastchar = 10 Then 'line feed (ascii 10) char received
        mymessage = fifobuff_readstring()
        mymessage = LeftStr(mymessage, Len(mymessage) - 1) 'remove line feed char
        fifobuff_lastchar = 0
        Lcdcmdout LcdLine1Clear
        Lcdout mymessage
Endif

Goto loop
End

On High Interrupt
        Dim arg1 As Byte
        Save System
        If PIR1.RC1IF = 1 Then
                UART_Get arg1
                Call fifobuff_write(arg1)
        Endif
Resume

Proc fifobuff_write(ByVal arg1 As Byte)
        If fifobuff_size = fifoN Then
                Exit 'code for the buffer overrun
        Endif
        fifobuff(fifobuff_writepoint) = arg1
        fifobuff_lastchar = arg1
        fifobuff_writepoint = fifobuff_writepoint + 1
        If fifobuff_writepoint = fifoN Then fifobuff_writepoint = 0
        fifobuff_size = fifobuff_size + 1
End Proc

Function fifobuff_read() As Byte
        If fifobuff_size = 0 Then
                Exit 'code for the buffer underrun
        Endif
        fifobuff_read = fifobuff(fifobuff_readpoint)
        fifobuff_readpoint = fifobuff_readpoint + 1
        If fifobuff_readpoint = fifoN Then fifobuff_readpoint = 0
        fifobuff_size = fifobuff_size - 1
End Function

Function fifobuff_readstring() As String
        fifobuff_readstring = ""
        While fifobuff_size > 0
                fifobuff_readstring = fifobuff_readstring + Chr(fifobuff_read())
        Wend
End Function