Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

Help understand assembly for C convertion

Status
Not open for further replies.

Hest

Junior Member level 1
Joined
Jun 14, 2011
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
Hello

I'm working with microprocessors and using hi-tech C for my programs.

I have an assembly program that I would like to re-make into C. The assembly code is for a PIC12f629 for modelcars with lights and blinking LED's.
I could just use it as it is, but I'd like to learn more my self and make some changes to it.

Because the code is so large, I have attached the ASM file as well as posted the code below:

DO NOT PUT 1500 LINES OF ASM CODE INLINE - ONLY INCLUDE THEM IN ATTACHMENTS

Here is a little code snip that explains my question.

Just an example. In the code he has got this:

Code:
R_CNT_F1    equ  30h          ; Counter for FLASH1
R_FLAG_F1   equ  31h          ; FLAGS for FLASH1
Code:
T_FLASH1    equ d'245' ; (1..255) duration of long off-time for FLASH1
T_BREAK1    equ d'45'   ; (1..255) duration of short off-time for FLASH1
Code:
movlw T_FLASH1      ; Time between 2 Flashes (long time)
btfss R_FLAG_F1,0    ; if short off-Time needed (Strobo double-flash)
movlw T_BREAK1      ; Time between 2 Flashes (short time)
subwf R_CNT_F1,W  ; if R_CNT_F1 < T_FLASHx / T_BREAKx
btfss STATUS,C       ; .. then 
return                    ; return
I can understand the most of the assembly code, but I can't figure out where this program is getting it's timing from and where those 245 and 45 comes in ans where he turns on and off those LED. I know what they mean, but not what counts it. It's really bugging me and I have played around with it for a while now.

I have been trying to figure out exactly how the program counts the time/ticks and decides what pin to turn on or off and when it resets and starts over. It's not timer0 because thats too fast. I think timer1 is used for every run through the program, but then I don't get why he only counts to 245 and 45 in his timings, because I tested that and that is way to fast.

I hope someone can guide me in the right direction and maybe explain to me a little more precise what happends and where those timings are used. Or maybe if someone could make just a small C example that uses some of his timings, so I can work from there.
 

Attachments

Last edited by a moderator:

T3STY

Full Member level 4
Joined
Apr 17, 2012
Messages
239
Helped
24
Reputation
48
Reaction score
24
Trophy points
1,308
Activity points
3,715
You may want to check the link, I wasn't able to download the file. Anyway, some general help:
The program gets its timing from the PIC main clock. Each second PICs execute an instruction in a time equal to 4/Clock_Freq, where Clock_Freq is the PIC clock. By knowing this you may calculate how much time passes when you execute a certain amount of instructions. When you need some delay you take into account this time and calculate how much time the PIC shall delay before executing the next useful instruction. That's where timing comes from. Probably the program also uses timers (like TMR0, TMR1) and prescalers which give a timing that's at minimum half of the main clock (prescaler minimum value is 1:2).
 

Hest

Junior Member level 1
Joined
Jun 14, 2011
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
The link is working for me, it's just a .txt file :) put it on another website instead http://vivaldi.dk/einsatz.txt maybe that is working

I know about the frequency and stuff, it's just the way he does his counting/timings I can't figure out. Maybe caling it timings is wrong, but I mean the way he does his checks on when to turn on and off his outputs.

I'm using the same settings as him and the same prescalers. Really hope someone can guide me a little in the right direction :)
 

wp100

Advanced Member level 5
Joined
May 15, 2009
Messages
3,056
Helped
883
Reputation
1,781
Reaction score
736
Trophy points
113
Location
Prime Meridian
Activity points
0
The link is working for me, it's just a .txt file :) put it on another website instead http://vivaldi.dk/einsatz.txt maybe that is working

I know about the frequency and stuff, it's just the way he does his counting/timings I can't figure out. Maybe caling it timings is wrong, but I mean the way he does his checks on when to turn on and off his outputs.

I'm using the same settings as him and the same prescalers. Really hope someone can guide me a little in the right direction :)

Hi,

Your dropbox link worked ok for me.

Thats 1000 lines of code, not easy to unscramble all his program flow.

The code builds ok in Mplab, and you can use Mplabs Sim to step though the code and watch what happens.

Use a breakpoint to allow skipping past the RamClear routine or remove that bit of code then F7 to step line by line.
You will have to change some of the code to tell it a switch is on, or use the Stimulus.
 

Hest

Junior Member level 1
Joined
Jun 14, 2011
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,436
Most of it is comments and copies of the same thing over and over, so I hope you would still look it over :)

I'll try to have a look at mplabs simulator. Never really figured it out because I'm used to use C
 

ALERTLINKS

Advanced Member level 4
Joined
Dec 13, 2003
Messages
1,259
Helped
395
Reputation
784
Reaction score
379
Trophy points
1,363
Location
Pakistan
Activity points
7,263
Code:
out4_blinker
        movf R_CNT_F4,W                ; get R_CNT_F4 into W-Register

        decfsz R_CNT_F4,F                ; if T_BILTZ4 is over..
         return                   

        movf GPIO,W
        xorlw b'00000010'              ; toggle OUT4
        movwf GPIO

        movlw T_FLASH4                 ; .. and
        movwf R_CNT_F4                 ; .. reload coumter

        return
Stay in main loop and,

Decrement a register
Test if it is zero
If not continue in main loop
If yes
do something
update register with pre-determined value for next delay
continue in main loop

This is multitasking. Program is not bound in delay loop. It counts delay of main program loop for number of times.
 
Last edited:

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top