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: 48
  • AD8307_Display.zip
    88.7 KB · Views: 40
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: 37
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: 25
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: 21
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: 26
- Error in line 30 (uncommented) - please see screenshot.
You pressed a key by mistake, because in the examples it is correct:
#define SIMULATION_WAITMS_VALUE = 1 'Enable for simulation


- 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
If you understood how the settings work it should work, otherwise the LCD will not be compatible.

Questions:
- Can "Define" and "#define" both be used in the source code?
Define = #define and #define = Define
Both are correct.


- Can "Lcdout" and "LCD_Out", and similars be used in the source code?
LCD_Out is a function I created, if the language doesn't have a function that does exactly what you want in most cases you can create it yourself. You can use both if you want.

- Define LCD_RSBIT = 1 --> Not 2, since RS-line is connected to pin RB2 on the PIC?
RS bit you have to declare it according to your schematic or hardware.

- 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).
According to the schematic you posted at the beginning your configuration for the LCD is as follows:
'LCD Port ---------------------------------------------------
'R/W is not used, connect to GND.
#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 = 2 'Bit RB2 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

The part of the LCD data bus that is not used I also connect to GND.
 
Last edited:
I have written a somewhat simpler code trying to make the LCD come alive.
Please find attached the .bas file and a screenshot of the simulator.
I believe, I am getting the hang of it! - Still, I didn't yet program a PIC to check the LCD in the hardware. Things are beginning to look promissing for my project!?
 

Attachments

  • LCD_test_01.bas
    1.7 KB · Views: 21
  • LCD_test_01 success.png
    LCD_test_01 success.png
    638.6 KB · Views: 26
Here is the schematic of the board with the PIC and the LCD module.
The mode selection jumpers are set for RB0=0 and RB1=0, i.e., the DC voltage from the
Log.-Detector unit (not shown) is connected to pin AN0/RA0 for A/D conversion.
After A/D conversion the calculated result (power in dBm) is fed to the LCD.
 

Attachments

  • LCM_Contrast.sch.jpg
    LCM_Contrast.sch.jpg
    187.6 KB · Views: 24
I programed a PIC with "LCD_test.hex" to check it in the hardware.
The desplay shows:
Top raw: "This is 1st line"
Bottom raw: "This is 2nd line"
Time to move forward with the code in OshonSoft Basic.
Thanks for all the help.
 
I am still strugling with a severe flu since end of December.
I certainly want to continue with my project as soon as I am fit again.
Happy New Year to all.
 
I my code compiles ok and can checke it with the simulator as well.
The only misssing part now is the A/D conversion routine and here I would need some help.
I think the A/D conversion can only be checked with the hardware, since an analog voltage
is needed for the input pin AN0.
In the present simulation I use as an example ADCRead = 0x1FF (half of the 10 bit range).
Please find attached the latest source code "V_dBm_Meter.bas" and a screenshot of the simulation.
Image1.png
 

Attachments

  • V_dBm_Meter.bas
    2.8 KB · Views: 8
You can simulate analog input voltage in simulation by using the microprocessor view interface (CTRL-V). If you click on the "A" beside the pin, an analog slider will appear. Set your voltage accordingly.
 
You have to configure the pin as analog input and select the reference source.

'ADC Configuration
#define ADC_Clk = 3 'ADC clock selection (range: 0 to 7, smaller value = faster)
#define ADC_Sample_uS = 20 ' ADC sample time in uSc (larger value = longer between readings)
'The values For ADC_Clk And ADC_Sample_uS depend On the conversion speed
'of the ADC module. Refer to the microcontroller datasheet for details.

'Key ADC registers involved in ADC operation:
'For detailed functionality of these registers, refer to the PIC datasheet.
ADCON0 = %0000001 'Set RA0 (AN0) as an analog pin.
TRISA.0 = 1 'Set RA0 (AN0) as an input
'ADCON0 is controlled by the ADC_Read function
ADCON1 = 0 ' Use VDD and GND as reference voltages (user controlled)
'ADCON2 is controlled by the ADC_Read, ADC_Sample_uS, and ADC_Clk settings


Lcdcmdout LcdClear
WaitMs 100
Lcd_Out(1,1,"RF-Power Meter")
Lcd_Out(2,1,"Hardware Rev.4")
WaitMs 500
Lcdcmdout LcdClear

main:
ADC_Read 0, ADCRead ' = 0x1FF 'Corresponds to 2.5 Volts
ADCResult = ADCRead*5/1024
'ADCResult = 2.5
Lcd_Out(1,1, "ADC OUT = " + #ADCResult +" V ")
dBmResult = (ADCResult-ZEROXING)*SLOPE
Lcd_Out(2,1, "PWR = " + #dBmResult + " dBm ")
WaitMs 500

'again:
'Insert code for A/D conversion

'Goto again 'Make a new A/D conversion
Goto main
End
 
For simulation I selected "3", but the display shows 0.01 V.
I guess I must be missing something in the subroutine GlobInit?!
 

Attachments

  • V_dBm_Meter.bas
    3.1 KB · Views: 4
  • Image1.png
    Image1.png
    832.3 KB · Views: 5
I don't see in your code where you set the A/D enabled as DogFlu mentioned:
ADCON0 = %0000001 'Set RA0 (AN0) as an analog pin.
That enables the A/D converter overall

Also, the slider values go from 0 to 1023, using a value of 3 will give such a low reading displayed. I just tried it with 748 and get a LCD readout of 3.65V.
 

Attachments

  • V_dBm_Meter.bas
    3.1 KB · Views: 4
Last edited:

Latest threads

New Articles From Microcontroller Tips

Back
Top