programma voor een p10f206 wijzigen naar een p16f84

Hallo beste circuitonliners,

ik ben op zoek om zelf een universele afstandsbediening te maken. De website van frits (picbasic) heeft me al heel wat geholpen. Verder vond ik op de site van microchip de application note AN1064 hierin staat er uitleg over hoe je een RC5 code moet uitzenden en een keer om Sony protocol uit te zenden, geschreven in assembler in MPLAB (http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&no…). Ik begin het programma zo wat te begrijpen. Maar het moeilijkste vind ik in het begin, vanaf mainloop lukt het me om te volgen:

-----------------------------------------------------------
; Ignore some warnings which are ok, but clutter the build output.
errorlevel -227 ; Ignore substituting pseudo-code "return" for real asm "retlw 0"

#include <p10f206.inc>

; Config Bits
__config _MCLRE_OFF & _WDT_OFF ; MCLROFF = set GP3 as digital input
; WDT_OFF = disable watchdog timer

;------------------------------------------------------------------
; PROGRAM CODE
;------------------------------------------------------------------

org 0 ; Processor Reset vector
; movlw d'42' ; Calibrate device's oscillator to 4MHz
movwf OSCCAL ; Load factory calibrated value from reset into osccal

; 10F20x have only 1 reset to org 0
; but this goto Main is for portability
goto Main ; redirect flow on powerup to Main label

Main:

Init:

; Initialize port functions and directions

; 10F20x parts must disable the comparator to use GPIO pins as I/O
bcf CMCON0, CMPON ; Disable comparator

; Also disable Timer 0, and enable pullups on inputs.
movlw b'00001000' ; Enable wake-up on change, pullups, and
option ; set prescalar to WDT to disable tmr0

movlw b'00000011' ; Define GP0, GP1 as inputs.
tris GPIO ; Load W into TRIS

bcf OUTPUT_LED ; Init output off
-----------------------------------------------------------

Nu heb ik er wel enkele regeltjes van tussen gelaten.

1) Wat wordt er bedoelt met errorlevel?
2) als ik p16f84a.inc ingeef gaat dit dan werken mits aanpassen van de pin nummers. (waar haal je deze include file?)
3) osscal d'42'. Ik heb geprobeerd om de uitleg te vinden aan de hand van de datasheet, maar dit is me niet gelukt.
4) wat betekent die option?

Alvast bedankt

ik ben niet zeker, maar dit is alvast mijn poging:

3) volgens mij is die d'42' mis. In het bestand voor sony protocol uit te sturen staat ze er zelfs niet. Bij het aflopen van het programma in MPLAB zie ik dat het werkregister op ff of 11111111 wordt geplaatst en dan wordt gezet in OSCCAL. Nu de LSB staat op 1 dus dit wil zeggen dat de INTOSC/4 op GPO2 terecht komt (of niet?).

Bijkomende vraag:indien je werkt met een extern kristal bij bv. een p16f84 is de frequentie dan ook gedeeld door 4?
Voor het uitzenden van een hoog bij RC5 moet je 889usec uitzenden, dus behoorlijk precies. Met het intern kristal van 4MHZ weet ik dat 1 cyclustijd overeenkomt met 1usec, maar in de datasheet van de 16f84 vind ik dit nergens terug.

waar waren we gebleven. 11111111. De overige 7 bits zijn de oscillator calibration bits. Als je zoals in het commentaar van de auteur de maximum frequentie nl 4MHZ wilt gebruiken, moet je dan niet 01111111 ingeven in het OSCCAL register?

4) option staat voor optionregister. Ze plaatsen de waarde 00001000 in het werkregister en dan gewoon option. Moet je niet:

movlw b'00001000'
movwf option

of is dit overbodig?

Als je met pics aan de gang gaat is het eerste wat je doet natuurlijk beide datasheets uitvoerig bestuderen.
Dan had je vraag 2 t/m 4 niet hoeven stellen.

over vraag 2 heb ik niks gelezen in de datasheet. En een datasheet begrijpen is nu ook niet altijd zo éénvoudig.

Je zult de verschillen tussen beide processors voor jezelf op een rijtje moeten hebben, dat betekent een lijstje maken wat de verschillen zijn.
Denk niet dat je door 'even' ergens een getalletje te veranderen je programma in een geheel andere controller wil draaien!

Letterlijk uit de datasheet van de 10F206:


9.2.2 INTERNAL 4 MHz OSCILLATOR
The internal oscillator provides a 4 MHz (nominal) system
clock (see Section 12.0 &#8220;Electrical Characteristics&#8221; for
information on variation over voltage and temperature).
In addition, a calibration instruction is programmed into
the last address of memory, which contains the calibration
value for the internal oscillator. This location is
always uncode protected, regardless of the code-protect
settings. This value is programmed as a MOVLW xx
instruction where xx is the calibration value and is
placed at the Reset vector. This will load the W register
with the calibration value upon Reset and the PC will
then roll over to the users program at address 0x000.
The user then has the option of writing the value to the
OSCCAL Register (05h) or ignoring it.
OSCCAL, when written to with the calibration value, will
   trim    the internal oscillator to remove process variation
from the oscillator frequency.

Misschien nog even dit: die 16f84 gaat steeds zeldzamer worden. Misschien toch even overwegen om naar een recenter type te gaan, bv 16f828. Zie ook http://www.voti.nl/picfaq/n_index.html voor meer info.

@ flipflop: bedankt voor de tip.