NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Total C virgin Newbie
January 07, 2010 by RICHRICH36 |
I will admit, I am a TOTAL NEWBIE. I am trying to get in the world of microcontrollers and the first thing I want to do is emulate credit pulses for some game machines that use digital coin acceptors. The following code was provided to me but I have absolutely no idea how to turn it in to something useful for the atmega. Anyone out there that wasnt to help me? ;*********** ;equates section tmr0 equ 1 ;means "tmr0" is file 1 status equ 3 ;means "status" is file 3 porta equ 5 ;means "porta" is file 5 portb equ 6 ;means "portb" is file 6 trisa equ 85h ;means "trisa" (the "porta" I/O selection) is file 85h trisb equ 86h ;means "trisa" (the "portb" I/O selection) is file 85h option_r equ 81h ;means the "option" register is file 81h zerobit equ 2 ;means "zerobit" is bit 2 count equ 0ch ;means "count" is file 0ch ;*********** list p=16f84 org 0 goto start ;*********** ;configuration bits __config h'3ff0' ;selects LP oscillator, WDT off, PUT on (Power On Timer), code protection ;disabled ;*********** ;subroutine section ;Coil Sense delay sense1 clrf tmr0 ;start timer0 loopa movf tmr0,w ;read tmr0 into working register sublw .5 ;time - 5 btfss status,zerobit ;check time - working register = 0 goto loopa ;time is not 0, so do it again retlw 0 ;time is 5, return to the last point in program ;Travel between sensors delay travel clrf tmr0 ;Led Sense delay sense2 clrf tmr0 ;*********** ;configuration section start bsf status,5 ;turns to bank 1 movlw b'00011111' ;5 bits of "porta" are inputs movwf trisa
;*********** ;Beginning of program: ;Button x1: add one credit each time pressed x1 btfsc porta,0 ;check if switch is pressed goto x10 ;switch wasn't pressed, check again!
;Button x10: add 10 credits each time pressed x10 btfsc porta,1 ;check if switch is pressed goto x1 ;switch wasn't pressed, check again!
repeat bsf portb,0 ;switch was pressed, send the first pulse call sense1 ;wait bcf portb,0 ;clear the first pulse call travel ;wait
END |
---|---|
January 07, 2010 by Rick_S |
It's hard for me to tell as I'm not totally familiar with it, but it looks like assembly to me not C. Rick |
January 08, 2010 by justin |
I got the same impression, Rick_S. RICHRICH36, I did a couple of quick Google searches, and I'm pretty sure that's PIC assembly. In other words, it's low-level instructions for a very different type of microcontroller. I'm sure that program can be translated into something that will work on the ATmega, but it looks like a task best suited for someone with some experience programming PICs. :-) Justin |
January 08, 2010 by mrobbins (NerdKits Staff) |
It does appear to be PIC assembly for a part number 16F84. I think that your best bet is to only look at the comments, and then write AVR C code that matches the description. BCF appears to be a "bit clear", and BSF is a "bit set" -- similar to the digital I/O bit manipulations we discuss extensively in The NerdKits Guide. Mike |
Please log in to post a reply.
Did you know that NerdKits has been featured in the MIT Undergraduate Research Journal? Learn more...
|