Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Moving from mikroBasic to OshonSoft Basic

bcz

New Member
I have built a project back in 2010 with the PIC18F2550 using mikroBasic.
A few weeks ago I damaged the PIC by connecting +13.8VDC to pin RA5.
Trying to program a new PIC with the original hex file using the same programmer fails.
I am using the programmer "brenner8p5" and the software "USBurn V1.13 a3" both by "sprut".
The programmer reports that there is no config in the source file and to use manual Config-settings.
To make it short, I can't fix the project.
I wonder if with your advice/help I could modify the code from mikroBasic's "pbas" to OshonSoft's "bas"?
I am not sure which CONFIG settings I should make if I had to start from scratch with OshonSoft Basic.
Please find some documents attached.
Kind regards,
Robert
 

Attachments

  • LCM_Contrast.sch.jpg
    LCM_Contrast.sch.jpg
    187.6 KB · Views: 27
  • AD8307_Display.zip
    88.7 KB · Views: 23
The code should be modifiable. Your "float" should be declared as "single" for floating point numbers. Also ASM instructions have to be declared on every line, ie:
ASM: MOVLW $7F
ASM: ANDWF INTCON2, 1
and so on...

LCD devices have to be defined in detail, like number of bits, port, which bit is what function, etc. LCDout is a single line output, you have to use other LCD commands to position the cursor.

As for config, your file shows the following:
Count=4
Value0=_FOSC_HS_1H = $00FC
Value1=_WDT_OFF_2H = $00FE
Value2=_LVP_OFF_4L = $00FB
Value3=_XINST_OFF_4L = $00BF
so that seems to be the only configuration bits changed from "default"

The Oshonsoft compile will include the config code into the Basic Source if you select it from the configuration window/panel to "Generate Basic Code"
 
Here is an example of how to start up the 1602A display that uses the HL-K18 card.
Caution the example has the MCLR pin activated.
 

Attachments

  • LCD1602A 46K22.bas
    4.6 KB · Views: 25
Last edited:
The code is quite compatible.
One restriction is that Functions and Sub have to come after END, that is, at the end of the program and after the general termination of the main function END. END in this language does not mean end of program, it means end of the main routine.
 
DogFlu66 and sagor1,
Thank you both for the very usefull comments and advice that will help me creating the new code.
Robert
 
I have been trying to modify and simplify my mikroBasic code I already attached in a previous posting.
Here I am attaching a few files in OshonBasic V_dBm_18F2550.zip.
Compilation and programming the PIC proved successful, i.e. no errors found, but the LCD shows only the 1st line with 16 square symbols in a static manner.
My first goal is to see the 2 lines of text being displayed on the LCD module of my project.
Only after I achieved this can I move on to extending the code with data fed to AN0 (A/D-converter).
-What am I missing?
- Can I use the "LCD Module" under "Tools" of the Simulator, instead of pluging and unpluging the PIC in the hardware in order to see what is displayed on the LCD?
Sorry if my questions are much too trivial in the Forum.
Thanks for any comments.
Robert
 

Attachments

  • OshonBasic V_dBm_18F2550.zip
    110 KB · Views: 5
Here's the problem:
#define LCD_DBIT = 0 ' Data bus 4, least significant bits of the port
#define LCD_DBIT = 4 'Data bus starts at bit 4, the most significant bits of the port


'Adaptation To LCD
'***********************************************************************
'Lines 3..8 copied from mikroBasic source code V_dBm_18F2550.pbas

'program V_dBm_18F2550
'Displays AD8307 Log.-Detector AC-in [dBm] versus DC-out [V] on LCD.
'MCU: PIC18F2550; Oscillator: HS, 20MHz; SW: mikroBasic build 7.0.0.2
'mikroBasic 4-bit default pin configuration for LCD initialization:
'D7, D6, D5, D4, EN, RS, RW - port(7..2, 0)
'Last change: 21.03.2010
'Using OshonSoft PIC18 Simulator IDE v5.72
'Options -> Configuration Bits -> Click "Generate Basic Code"
#define CONFIG1L = 0x00
#define CONFIG1H = 0x0C
#define CONFIG2L = 0x1E
#define CONFIG2H = 0x1E
#define CONFIG3L = 0x00
#define CONFIG3H = 0x83
#define CONFIG4L = 0x80
#define CONFIG4H = 0x00
#define CONFIG5L = 0x0F
#define CONFIG5H = 0xC0
#define CONFIG6L = 0x0F
#define CONFIG6H = 0xE0
#define CONFIG7L = 0x0F
#define CONFIG7H = 0x40
#define CLOCK_FREQUENCY = 20
#define STRING_MAX_LENGTH = 30
#define SINGLE_DECIMAL_PLACES = 2 ' Number of decimal places for floating point numbers
'#define SIMULATION_WAITMS_VALUE = 1 'Enable for simulation
'LCD Port ---------------------------------------------------
#define LCD_BITS = 4 'LCD data bus, configured To 4 bits
#define LCD_DREG = PORTB 'Data bus, assigned to port B
'#define LCD_DBIT = 0 ' Data bus 4, least significant bits of the port
#define LCD_DBIT = 4 'Data bus starts at bit 4, the most significant bits of the port
#define LCD_RSREG = PORTB 'RS control bit, assigned to port B
#define LCD_RSBIT = 1 'Bit RB1 assigned As RS
#define LCD_EREG = PORTB 'E control bit, assigned to port B
#define LCD_EBIT = 3 'Bit RB3 assigned as E
#define LCD_COMMANDUS = 2000 'Wait time after each command in microseconds
#define LCD_DATAUS = 100 'Wait time after sending data to the LCD in microseconds
#define LCD_INITMS = 50 'Wait time for display initialization in milliseconds

AllDigital
Lcdinit

Dim ZEROXING As Single 'Volts measured at AN0/RA0 for 0 dBm RF input
Dim SLOPE As Single 'Conversion slope measured as dB/V
Dim ADCResult As Single
'Dim 0ldResult As Single
Dim VoltsDisplay As String
Dim dBmResult As Single
Dim dBmDisplay As String

Dim x As Byte
x = 1
Dim Adc As Single
Adc = 5.25

main:
'Gosub GlobInit
Lcdcmdout LcdClear
WaitMs 100
'Lcdout " RF-Power Meter"
Lcd_Out(1, 1, " RF-Power Meter")
'Lcdcmdout LcdLine2Home
'Lcdout " Hardware Rev:4"
Lcd_Out(2, 1, " Hardware Rev:4")
WaitMs 100
Lcd_Out(2, 16, #x)
WaitMs 2000
Lcdcmdout LcdLine1Clear
Lcd_Out(1, 1, " " + #Adc + "V")
WaitMs 2000
Goto main
End
'Function Lcd_Out(line, pos, String_Value) de MicroBasic
Function Lcd_Out(line As Byte, pos As Byte, txt[20] As String) As Bit
If line = 0 Then line = 1
If line > 2 Then line = 2
If pos = 0 Then pos = 1
If line = 1 Then
Lcdcmdout LcdLine1Pos(pos)
Else
Lcdcmdout LcdLine2Pos(pos)
Endif
Lcdout txt
End Function
 

Attachments

  • V_dBm_18F2550.bas
    4.1 KB · Views: 4
Last edited:
- Error in line 30 (uncommented) - please see screenshot.
- The commented version compiles OK, but with the programmed PIC in the hardware
the LCD still shows only the top row with 16 square symbols.
Questions:
- Can "Define" and "#define" both be used in the source code?
- Can "Lcdout" and "LCD_Out", and similars be used in the source code?
- Define LCD_RSBIT = 1 --> Not 2, since RS-line is connected to pin RB2 on the PIC?
- Where can I find the MOST up-to-date version of manual, help file, etc.?
I would be very greatful for any simple code examples with 2-line 16-characters/line LCD implementation (possibly with the most up-to-date code syntax). I think could find answers to a few more of my unasked questions).
 

Attachments

  • Error in Line 30.png
    Error in Line 30.png
    550.5 KB · Views: 3

New Articles From Microcontroller Tips

Back
Top