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.

CH Basic

Status
Not open for further replies.

grim

New Member
anyone else played with this? It's a free demo for the sample versions (usual limitations)

but it shows the assebmler language as you enter the basic commands.

**broken link removed**

even if you dont use it as a language tool, as a guide how to achieve things it looks good.

well i was impressed:D

homepage
 
I've used an older version but it suffers from one fatal flaw - it's BASIC. :D

As BASICs go, it's decent and you can't argue with free. Oddball collection of supported PICs, though. It supports the 628, 84 and 877 so it's ok for hobbyists. No support for the F88 in the demo version.
 
CH was OK in it's day, but is out of date...

The documentation for the Flash version is copyrighted 2001. The Q&A page was last updated March of 2002. It doesn't support I2C, you have to roll your own. This is yet another good compiler left to go to seed.

I am impressed with how selection menus come up with access to all the available registers and gates inside the chip you selected to use. So, if the PIC you selected had one comparator, the comparator menus had initialization, set ups and functions for one comparator. If the PIC had two comparators, it had all of the previous possibilities, but for two comparators. The same goes for PWM, ADCs, etc. Everything you had to do, and could do, was in those menus. It was great for people adverse to read data sheets. There were other menus/lists that let you track variables used, and the list goes on.
To my mind the best feature of this compiler is the instant assembler code created on the spot as you entered a line of BASIC source. Just the thing for students.

I purchased the Flash 3.7 version in early 2004 for $97. They brought out ver.4 shortly after. They didn't support the 18F family as hoped. Instead they basically revamped the layout and icons. Big deal. Not worth the $upgrade.
At $188 for the Flash4, I can't recommend this for what you get, although it does have some neat features.

CH BASIC is the OTHER whiz-bang compiler I bought in 2003/2004 that showed real promise, then languished without meaningful upgrades. The first (Sept 2003) cost $230, so that was really painful, especially since I got it after they said the next major upgrade was due before Christmas. Three years later they are finally making all the right noises , but...

Check out Oshon Software at https://oshonsoft.com/. He has two compilers, one for PIC16Fs, another for PIC18Fs. A bundle license for both these is 55 euros ($70.52 as of 11/16/06). These are the FULL compilers, not some halted version, and does many, many PICs. You can buy a license for one or the other for considerably less. This gets you the 32-bit math package and structured features packages for both. These two features can be purchased as separate from the compilers, for people that buy the REALLY LAME compiler(s) version(s) at lowest price.
If you want to add USB capabilities to the 18Fs that support it, you'll have to buy a separate license for 75 euros ($96.17 etc.).
All these prices given here are for the PERSONAL/HOBBYIST VERSIONS!! Commercial licenses are more.
There are two forums for these products, both weak on performance. You can find answers there, but the author is good about responding to questions, so the forums are almost unnecessary.

And, of course, there is MikroElectronica's BASIC. It too is quite capable. But, it is heavilly structured, not too friendly to beginners. The developers say as much, they had the semi-professional in mind. Their BASIC can be had for $99 as a download if you buy their development board (the EZPIC4, a perfectly GORGEOUS device, check it out!) for $145 (includes $25 for shipping). Look them up at https://mikroe.com/.
Their forums are large and dynamic, with several knowlegable people lending their wisdom. And barbs.

For what it's worth,
kenjj
 
good review kjennejohn:D

yes, it was the instant conversion of basic to assembler that drew my attention.
as they say in their bit, a great learning tool.


I am downloading as many freebies as I can, to get a feel for what is out there, before splashing some cash - and of course playing with assembler too.
 
Well, yes and no...

gramo said:
Assembler and C are dieing breeds and higher level programming suits(pic and pc based) are taking over more everyday. There’s no need to re-invent the wheel :p

What cant you do with Proton+

Assembler will never go out of style. The only programming more elemental than assembler is entering the hex values for the op codes and data by hand into a file. Assembler is the lowest, user-friendly language to program from. But, you have to have an iron clad understanding of the chip's workings to program it. And THAT is a lot of work.

C is one of the next steps up. It is a little friendlier; the compiler's author has provided the necessary language that writes code that knows the workings. BUT, the assumptions he/she make about the best way to do it may be inefficient, if not downright wrong. Also, they may provide varying amounts of bullet-proofing to keep the user from shooting their toes off, anywhere from none, to intrusive and unyielding.
C's main claim to fame is forcing a structure on the user to create (they hope) readable, maintainable, reusable code. And now with Object Oriented Programming you come to C++ and the rest, and it's damn near harder than assembler.

Good ole BASIC. Programming for the masses, balm for the enthusiastic beginner and/or student. The trend seems to be to provide a simple BASIC that will allow someone to just bang out code to blink LEDs, then build on that with free updates (we can only hope). The intermediate users will buy it 'cause it's inexpensive, try doing commercial work with it, then badger for more commands/features/functions/utilities/etc. The author will obligingly (yeah, right) add all this until the language becomes some bloated, structured lumbering beast that needs a six-part forum and email support to learn how to blink LEDs over the Web. And costs $265 for the downloadable version.

Hey! That last tirade sounds like Proton+! Except that the other BASICs give you a free In Circuit Debugger, and P+ sends you to a 3rd-party offering that costs an extra $65!
So, what can't you do with Proton+? Ummmm...pay the rent?

Whatever,
kenjj
 
gramo said:
Assembler and C are dieing breeds and higher level programming suits(pic and pc based) are taking over more everyday. There’s no need to re-invent the wheel :p

What cant you do with Proton+
well, that's a refreshing point of view. too bad it's completely out of sync with reality. You could possibly make an argument that they provide an obsolete programming paradigm but I'd still say you were way off. In terms of what code gets written in which languages, it depends on the microprocessor but it will either be C/C++ or asm in first place and the other in second. any other language is a far far distant noise level 3rd place, probably basic.

the proton question is just silly, If you work hard enough, you can do just about anything in any language. Though the effort may not be justified by the return and the result might not be very pretty.
 
Last edited:
As for BASIC compilers that show you the assembler code, here's the assembly listing produced by my WinPicProgB BASIC compiler/programmer, it inserts the basic lines as comments in the assembler source code.

Code:
; WinPicProg BASIC Compiler Version1.91
;
; Device 16F876
    LIST P=16F876, W=2, X=ON, R=DEC
    #INCLUDE P16F876.INC
    __CONFIG    0x393A
;Flags register bit definitions
LEADZ         EQU   0x00   ;set to show leading zeros
OverFlow      EQU   0x01   ;set for add/sub overflow
Lo            EQU   0x05   ;set for I2C normal addressing
Hi            EQU   0x06   ;set for I2C extended addressing
Err           EQU   0x07   ;set for I2C error
;Pre-defined variables
TEMP1         EQU   32
TEMP2         EQU   33
RESTORE       EQU   34
TEMP1_DU      EQU   35
TEMP2_DU      EQU   36
RESTORE_DU    EQU   37
W_DU          EQU   38
STATUS_DU     EQU   39
Bit_Cntr      EQU   40
Xmit_Byte     EQU   41
Rcv_Byte      EQU   42
LCD_DAT1      EQU   43
Delay_Count   EQU   44
_N            EQU   44
LCD_DAT2      EQU   45
LCD_DAT3      EQU   46
TEMP_LCD      EQU   47
TEMP_LCD2     EQU   48
DELAY1        EQU   49
state         EQU   50
pin           EQU   51
hiRnd         EQU   52
lowRnd        EQU   53
Acc1L         EQU   54
Acc1H         EQU   55
Acc2L         EQU   56
Acc2H         EQU   57
Acc3L         EQU   58
Acc3H         EQU   59
Flags         EQU   60
TenK          EQU   61
Thou          EQU   62
Hund          EQU   63
Tens          EQU   64
Ones          EQU   65
Adr_Lo        EQU   66
Adr_Hi        EQU   67
Chip_Adr      EQU   68
Data_Page     EQU   69

; Macros
fcall    macro subroutine_name
    local here
    lcall subroutine_name
    pagesel here
here:
    endm

    ORG      0x0000
    NOP      ;for bootloader compatibility
    NOP
    NOP
    GOTO     _START1
    ORG      0x1800
    #INCLUDE MATHS.INC
    #INCLUDE HANDLERS.INC
    ORG      0x0010
_START1
    CLRF     RESTORE
    CLRF     Flags
    BCF      Flags, LEADZ
    BANKSEL  ADCON1
    MOVLW    0x06
    MOVWF    ADCON1
    BANKSEL  PORTA
; Dim A,I,B
VAR2    EQU      70;A
VAR4    EQU      72;I
VAR6    EQU      74;B
; Define PortA=%11111111
    BANKSEL  TRISA
    MOVLW    255
    MOVWF    TRISA
    BANKSEL  PORTA
; Define PortC=%00000000
    BANKSEL  TRISC
    MOVLW    0
    MOVWF    TRISC
    BANKSEL  PORTC
; Define PortB=%00000000
    BANKSEL  TRISB
    MOVLW    0
    MOVWF    TRISB
    BANKSEL  PORTB
; Set(ADC_Channel=0)
    MOVF     ADCON0,W
    ANDLW    0xC5
    IORLW    0x00
    MOVWF    ADCON0
; Set(ADC_Config=14)
    MOVLW    0x0E
    BANKSEL  ADCON1
    MOVWF    ADCON1
    BSF      ADCON1,ADFM
    BANKSEL  ADCON0
; Set(ADC_Clock_Source=CLOCK/8)
    BCF      ADCON0,ADCS1
    BSF      ADCON0,ADCS0
; I=0
    MOVLW    0
    MOVWF    VAR4+1
    MOVLW    0
    MOVWF    VAR4
; OUTC(0)
    MOVLW    0
    MOVWF    PORTC
; OUTB(0)
    MOVLW    0
    MOVWF    PORTB
; Loop:
LAB1:
; Start(ADC)
    BSF      ADCON0, ADON
    BSF      ADCON0, GO_DONE
    BTFSC    ADCON0, GO_DONE
    GOTO     $-1
; Delayms(255)
    MOVLW    0
    MOVWF    Acc1H
    MOVLW    255
    MOVWF    Acc1L
    fcall    _DELAYMS
; Delayms(255)
    MOVLW    0
    MOVWF    Acc1H
    MOVLW    255
    MOVWF    Acc1L
    fcall    _DELAYMS
; Delayms(255)
    MOVLW    0
    MOVWF    Acc1H
    MOVLW    255
    MOVWF    Acc1L
    fcall    _DELAYMS
; Delayms(255)
    MOVLW    0
    MOVWF    Acc1H
    MOVLW    255
    MOVWF    Acc1L
    fcall    _DELAYMS
; A=ADC_ResultL
    BANKSEL  ADRESL
    MOVF     ADRESL,W
    BANKSEL  ADRESH
    CLRF     Acc1H
    MOVWF    VAR2
    MOVF     Acc1H, W
    MOVWF    VAR2+1
; B=ADC_ResultH
    MOVF     ADRESH,W
    CLRF     Acc1H
    MOVWF    VAR6
    MOVF     Acc1H, W
    MOVWF    VAR6+1
; OUTC(B)
    MOVF     VAR6,W
    MOVWF    PORTC
; OUTB(A)
    MOVF     VAR2,W
    MOVWF    PORTB
; Goto Loop
    GOTO LAB1
; end
    CLRWDT
    SLEEP
    END
;
;Number of variables used:74 out of 127
 
of course if you want to get a program working this afternoon, and aren't fussy what chip to use, then basic is great:D

Assembler has a lot of advantages over all the high level languages, size and speed of code being the obvious ones, but a less obvious one being you aren't restricted to programming the pics the high level language was written for.

I am sure this is a problem that you experience Nigel - you support the chips that you feel are the best ones out there - but they may not be the chips i want to use!

unless i have missed something do any of the basic/c languages support every pic out there, and keep up with microchip developments like mpasm does?

(forgive me if that's a naive question)

or is there an open source programming language, where users can contribute pic description files?

alternatively how easy is it to take the code written for one chip, and alter it for an unsupported one?

so i want a high level code, that supports every chip i could want, produces fast neat code, and is avaliable as shareware:D not much to ask, surely:D :D :D :D
 
grim said:
unless i have missed something do any of the basic/c languages support every pic out there, and keep up with microchip developments like mpasm does?

No, and it's unlikely there ever will be, it's not really possible - unless MicroChip hold back the release of new chips for a number of months, and send pre-production samples to all the language writers.

so i want a high level code, that supports every chip i could want, produces fast neat code, and is avaliable as shareware:D not much to ask, surely:D :D :D :D

Would you like next weeks lottery numbers as well? :D
 
Euro lottery numbers if you have them:D

I wasn't expecting everyone to keep right up to date with microchip, that would be asking a bit much - but it seems that every one i look at supports three or four chips i am interested in, so i need multiple software to cover everything.

but anyway, that's running before i can limp again;)
 
Just on basic development suits,

I guess some people have different interpretations of the basic language. There are many suits out there, many paths for pic programmers to take, although many similar, none are the same.

The diversity of Proton+ is far more than many people really stop to consider, and is sometimes based on predeceasing suits that have lead people to the belief that basic does not offer the same constructive benefit that low level languages offer.

I'd have to say that seamless integration of 32bit math in proton is definitely a highlight, that and controlling I2C/UART/SPI/dallas 1 Wire/any serial communication is just as smooth. I'd hate to spend my time developing routines to do the following from scratch;

Code:
Dim Number1 as Float
Dim Number2 as Float
Dim Result as Float

Number1 = 1000 / 500.23		
Number1 = (Number1 - 0.5) * 10		

Number2 = Number1 / 2.551 * 10000		

Result = (Number1 + Number2) / 2.597	

Print At 1,1, Dec Result	   		' Display data on a LCD


Value = ADIN 0	  		 	' Perform an ADC on channel 0

EWRITE 00,[Value]	  			' Write to eeprom address 0
Value = EREAD 00				' Read from address 0

For X = 1 to 10, Step 2			' Fill an array with random data
	Storage[X] = Random		'  Random will return a random number between 0-65535
Next X

Repeat		   	 		' Create a looping condition 
	   X = X +1
Until PORTA.1 = 1 And X = 10		' Exit only if porta.1 = 1 and x=10

Thousands = Dig Value,3	  		' Extract the 4th digit(thousands) from the value

Delayms 10000				' Create some delays
Delayus 1									' 

HPWM CCP1, 128, 2000			' Create a PWM with duty of 50% and 2Khz
HPWM CCP2, 64, 25000			' Create a PWM with duty of 25% and 25Khz

PULSOUT PORTB.0, 100, High		' Send a high pulse for 10ms on PORTB.0

Value = COUNTER PORTB.1, 100		' Count every pulse on PORTB.1 for 100ms						

SERVO Pin , Value				' Tell a servo to turn to an exact position 


BStart	  				  ' Send the start command on I2C
BusOut %10100010,00,[Value.HighByte]  	  ' Send the word to the eeprom
BStop
Delayms 5
BStart	  				  ' Send the start command on I2C	 
BusOut %10100010,00,[Value.LowByte]  	  ' Send the word to the eeprom	 
BStop		
 
SEROUT PORTA.0 , T9600 , [ DEC Value ]	  ' Send data via software USART
SHOUT DTA , CLK , MSBFIRST , [Value]	  ' Send data via SPI 

OWRITE DQ, 1,[$55,Address_L, Address_H,Value, Value]	 ' Via 1 wire protocol

This program is not designed to do anything, just a quick overview of some basic features in Proton+, and there’s many many more. I'd have to admit that a major flaw of high level programming was loosing the ability to control interrupts as efficiently, but as of late, hardware interrupts are now fully supported via a plug-in called bisvs (a macro that checks all the software commands, and automatically saves only the compiler system registries in use, and restores them afterwards).

Proton takes the mundane bit crunching, all night debugging heart aches out of programming. But if learning how to develop your own I2C/SPI/USART routines, or your own 32bit math handling routines is your style, then by all means, assembler is the way to go.

If you have the cash, the real savings are in your actual time. Weather it be using Proton for development, or with a VSM for example, I can design the circuit, throw in Logic analyzers, AC/DC volt/amp meter, oscilloscopes, virtual terminals, I2C debuggers, signal/pattern generators and simulate the circuit with choices of thousands of components available in real life.

ARES is probably the best PCB development tool out there as well, and integrates with ISIS to auto route the circuit on 1,2,or multilayer PCB, then just press and peel the boards.

If by the remote chance I have to do something as efficient as possible, I would simply use the following in the project,

ASM
'asm code goes here
ENDASM

But seriously, how often is it that critical to use programming at asm level? Anything that has a timing issue can be resolved by using accurate TMR0/TMR1 interrupts, and instantaneous detection of pin changes can be used via the PORTB change interrupt.
 
Last edited:
gramo said:
Assembler and C are dieing breeds and higher level programming suits(pic and pc based) are taking over more everyday. There’s no need to re-invent the wheel :p

What cant you do with Proton+

Write a small program without it telling you to remove some lines in the demo?

Why I aborted it. A simple program (or a few of them). I tried it, I ran out of room to test it in the demo. And stung by others I bought I was not willing to part with more money.

I moved on. MikroBASIC works for me. When I am 100% comfortable with it. I will take the extra bloat and buy it.

Mind you I have fell back to assembler a few times after I saw the time I wasted.

I do think Proton is the one I want, but if I can not write a small program in it without running out of lines (they are not a hobby compiler but their demo seems to be geared that way). And I will not steal it to see if it is really the answer. They need to open it to 500 lines or more so people can see they have a good product.

So my answer to the original poster. Look at Mikrobasic. I import the .hex in MPLABS, open their .ASM in notepad+ and work from there. It is not that bad.
 
Nigel Goodwin said:
As for BASIC compilers that show you the assembler code, here's the assembly listing produced by my WinPicProgB BASIC compiler/programmer, it inserts the basic lines as comments in the assembler source code.

And where do I download this WinPicProgB BASIC compiler? I will bite?
MPLABS code too??
 
Nigel Goodwin said:
Sorry, you don't, it's not been released :(

I was checking to see if it was for real for a joke? I went, Nigel, PIC and BASIC. But you can see all the people looking for the right solution.

From MicroChip, a free download.

Oh I use that and Mikrobasic now, and it is not too bad. But a MPLABS compatible ASM file and BASIC lines inserted as comments.

The only reason I like BASIC for the microcontrollers, you pick a chip and it does the init for the chip, you do ADCinput(port,pin) and it sets up the pic. Do for quick projects it really has a place and really good to start new people on the PICS.

Honestly, PICbasic with a proper IF THEN ELSE ENDIF and maybe ADC command would be all I would ever need. I have no problem with a .ASM and .ASMEND as lond as I can get to the variables.
 
mramos1 said:
Honestly, PICbasic with a proper IF THEN ELSE ENDIF and maybe ADC command would be all I would ever need. I have no problem with a .ASM and .ASMEND as lond as I can get to the variables.

Sorry about this - but this is from the documentation of my uncompleted BASIC compiler!

There is also an advanced version of IF/THEN available, IF/THEN/ELSE/ENDIF, this allows more advanced program structures to be written, you may have multiple lines between the THEN, ELSE and ENDIF sections.

This is how to use the ADC!

Code:
Device 16F876
Dim A,I,B
Define PortA=%11111111
Define PortC=%00000000
Define PortB=%00000000
	Set(ADC_Channel=0) 'will use pin RA0 for AD input
	Set(ADC_Config=14) 'option 14 only A0 is used
	Set(ADC_Clock_Source=CLOCK/8)
	I=0
	OUTC(0)		'clear OP display
	OUTB(0)
Loop:	Start(ADC)
	Delayms(255)
	Delayms(255)
	Delayms(255)
	Delayms(255)
	A=ADC_ResultL	'get results
	B=ADC_ResultH
	OUTC(B)		'display them
	OUTB(A)	
	Goto Loop
end
 
Last edited:
Nigel Goodwin said:
This is how to use the ADC!

Code:
Device 16F876
Dim A,I,B
Define PortA=%11111111
Define PortC=%00000000
Define PortB=%00000000
    Set(ADC_Channel=0) 'will use pin RA0 for AD input
    Set(ADC_Config=14) 'option 14 only A0 is used
    Set(ADC_Clock_Source=CLOCK/8)
    I=0
    OUTC(0)        'clear OP display
    OUTB(0)
Loop:    Start(ADC)
    Delayms(255)
    Delayms(255)
    Delayms(255)
    Delayms(255)
    A=ADC_ResultL    'get results
    B=ADC_ResultH
    OUTC(B)        'display them
    OUTB(A)    
    Goto Loop
end

Too bad you did not finish it. Oh well.. I will stick to mikrobasic and MPLABS for now. Last project did not go as fast as I would have liked, but it is done now and it was a learning process. Turned out to be something dumb and in MPLABS, not the BASIC. :) I did not have a bit set right on the 16F88
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top