Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Discuss about PIC Programing Languages

Status
Not open for further replies.
I program in Assembly. How do you guys use higher level languages for time critical applications since you don't know exactly how long the compiled code will take to execute? Here's a simple example:

using a PIC16F84 at 4 Mhz, you want to toggle RB0 every 10uS. In assembly, I may write:

Code:
bsf STATUS, RP0      ;bank 1
movlw B'11111110'
movwf TRISB           ;set RB0 as output
bcf STATUS, RP0      ;bank 0
LOOPFOREVER:
movlw 1
xorwf PORTB, f        ;toggle
goto $ + 1
goto $ + 1
goto $ + 1
goto LOOPFOREVER ;delay, loop = 10 cycles

How would I write it in PICBasic Pro or C?

What would the size be in terms of general registers used and program words? The assembly code is 0 registers and 10 program words.
 

you are right jonw0224 but in complecated applications, say mathematical calculations C is simpler than assemply ..
it is easy yo say
num1=porta;
num2=portb;
result=num1+num2;

shafee
 

shafee,

I agree with you. I think your example is trivial in assembly as well:

Code:
movf PORTA, w   ;w = PORTA
addwf PORTB, w           ;w = PORTA + PORTB
movwf result                ;result = PORTA + PORTB

Or, if you need to store num1 and num2 for later:

Code:
movf PORTA, w
movwf num1
movf PORTB, w
movwf num2
addwf num1, w
movwf result

The compiler makes the decision I imagine. The second is a bit harder and it gets harder with each level of complexity in the program. I've always personally been a proponent of MACROS. For example, you can simplify the second as:

Code:
MOVFF macro regA, regB
movf regA, w
movwf regB
endm

ADDFF macro regA, regB, dest
movf regA, w
addwf regB, dest
endm

MOVFF PORTA, num1
MOVFF PORTB, num2
ADDFF num1, num2, w
movwf result

The macros can be declared in an .inc file (once) and you'll only have to write the four lines. If you wrote more complicated macros you could shorten it to three. Really, I think the benefit to using upper level languages is that the writers of the compiler draw on a set of prewritten code segments to make connecting the dots easier. Libraries are the power of C, PICBasic Pro, etc. over assembly. Many tasks are prewritten, so people don't have to worry about how to write them or how they work. The best compiler will have, among other things, the most extensive library that's easy to understand and use and works across many microcontrollers.

This is only my opinion.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top