Forum: Mikrocontroller und Digitale Elektronik PIC16f84a Frequenz


von Hasan S. (hasansivan)


Lesenswert?

Hallo ich habe folgendes Problem SSOL Rutine soll 784 Hz betragen, ich 
komme einfach nicht auf die 784 Hz.
Kann mir jemand helfen wie man darauf kommt der PIC wird über einen 
Externen Oszillator betrieben über ein RC Glied = 1 MHz

Darunter ist die Warteschleife zu sehen


DELAY  nop      ;[\ 5 cycles of 4 microsec.
  nop      ;[\ = 20 microsec.
  incfsz  count,f    ;[/ x 256=5120 microsec.
  goto  DELAY    ;[/
  decfsz  del,f    ;delay = 5120 x del.(2 units of
  goto  DELAY    ;del equal ebout 10 millisecondes).
  return


SSOL  movlw  d'204'    ;G deep complement to 256 = 52
  movwf  freq    ;frequency of the beap
  movlw  d'192'    ;comp. = 64: number of pulses
  movwf  long    ;(execution time of the beap)
  goto  bip    ;emmitting beap

von Chris B. (dekatz)


Lesenswert?

Was soll 784 Hz betragen? Soll die SSOL Routine 784 x pro Sekunde 
aufgerufen werden? Und was macht die DELAY Routine welche auch nie 
Aufgerufen wird (und für eine 784Hz Timing ohnehin viel zu lange dauert)

Die beiden Codefragmente können ja nicht alles sein und mit einem 
RC-Oszillator irgendeine genaue und halbwegs stabile Frequenz zu 
erzeugen ist....sportlich.

Poste mal was du überhaupt machen willst.

von Hasan S. (hasansivan)


Lesenswert?

Hier ist der Code es ist ein Codeschloss.

Quelle : Elektor

So wenn man nach korrekter Eingabe die Taste 7 drückt ertönen Töne mit 
bestimmte Frequenzen.

Meine Frage ist jetzt wie man auf die Frequenzen kommt die da abgespielt 
werden.

Töne : G5 = 784 Hz, C6 = 1047 Hz , E6 = 1319 Hz und G6 = 1568 Hz


;                              CODEUR 4X15   Program   in Microchip 
assembler                  ;
;                                                         PIC16F84A 
;
;___________________________________________________________________ ;
;   External oscillator RC 1 Megacycles.     Instruction = 4 
microsecond.                       ;
;   C=100pf R=6400 ohms (Pot. 10k) 
;
;....................................................................... 
................................................................;
;   Ports affectation:      Ra0:   output Load capacity for Beep 
execution                        ;
;                                    Ra1:   output Emission beeps 
;
;                                    Ra2:   output Relay N° 3 for 
trigger                                            ;
;                                    Ra3:   output Relay N° 2 
;
;                                    Ra4:   input   Special procedure 
(strap)                                     ;
; 
;
;                                    Rb0:   output Relay N° 1 
;
;        For keyboard...    Rb1-3: output Keyboard Exploration 
;
;        Matrix  4x3 .....     Rb4-7: input Receive exploration keyboard 
;
; Awake of the microprocessor bye change on Rb4-7 inputs 
;
; Watch dog timer is in use (about 2.1 second) 
;
;___________________________________________________________________;
  list p=16f84a,f=inhx8m    ;assembler output hexadec. 8bits
  __config h'3ff7'    ;WDT enable; external RC oscill.
  __idlocs h'BC01'    ;chip identification
  org 0x2100    ;Eeprom 64 bytes
 de 0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff  ;eeprom address 0-7 = FF
          org 0x00      ;Program memory address = 0
w  equ  0    ;working register
f  equ  1    ;result to file: (memory byte)
z  equ  2    ;zero (bit 2 = zero status word)
;1- memory addresses reserved to the processor
indf  equ  0x00    ;indirect addressing
status  equ  0x03    ;status word address
fsr  equ  0x04    ;indirect addressing offset
porta  equ  0x05    ;port A address
portb  equ  0x06    ;port B address
trisa  equ  0x05    ;config port A in bank1 output
trisb  equ  0x06    ;config port B in bank1 output
optreg  equ  0x01    ;option register in bank1
intcon  equ  0x0b    ;interrupt control bank0 or 1
eeadr  equ  0x09    ;EEPROM addressing
eedata  equ  0x08    ;EEPROM data
eecon1  equ  0x08    ;EEPROM control1 in bank1
eecon2  equ  0x09    ;EEPROM control2 in bank1
;2-Variables of the programm
freq  equ  0x0c    ;freq.beap(first adress Ram user)
long  equ  0x0d    ;emission time for one beap
count  equ  0x0e    ;counter
pswdok  equ  0x0f    ;bool = 1 if valid code entered
del  equ  0x10    ;counter delays
delerr  equ  0x11    ;penalty time after 4 errors
fcode  equ  0x12    ;returned code keyboard analysis
toc  equ  0x13    ;counting time out of WDT
pwlong  equ  0x14    ;register lenght of secret word
svpwlin  equ  0x15    ;save pwlong
pswdn  equ  0x16    ;register 1 char. Of Secret code
err  equ  0x17    ;number of errors
sound  equ  0x18    ;bool beaps: 0=enable 1=disable
  cblock  0x20    ;block Registers maxi 16 char.\
  fpsw      ;    (length + 15 char.)              ]
  endc      ;    (0x20 to 0x2f)                     /
;In the program commentary pwd or pswd means password = secret code.

delays  macro  arg1    ;macro delays. argument contains
  movlw  arg1    ;number of 5120 microseconds
  movwf  del    ;del = quantity from the program
  call  DELAY    ;line x bye 5120 microseconds.
  endm
;................beginning program at address 0................
Init1  bsf  status,5    ;bank1
  movlw  h'08'    ;int.dis.bit0 = flag rb change          \
  movwf  intcon    ;enable interrupt on Rb4-7 change/
  movlw  h'8f'    ;prescaler 128 to WDT (2,1sec.) \
  movwf  optreg    ;and disable pull-up res. port b    /
  movlw  h'10'    ;port a 0-3 out 4 in  \
  movwf  trisa    ;init trisa 00010000 /
  movlw  h'f0'    ;port b 1-3 out toward keyboard \
  movwf  trisb    ;4-7 input keyboard.  0 out RL1  /
  bcf  status,5    ;bank0
  clrf  porta    ;init port A all 0
  btfsc  status,4    ;not modify sound if WDT time out
  clrf  sound    ;sound permit at power on
  call  SOL    ;3 beaps shrill
  call  SOL    ;Ending init1 after power on
  call  SOL    ;sol = Note G
  clrwdt      ;clear watch dog timer
Init2  clrf  eeadr    ;address EEPROM = 00
  clrf  porta    ;init port a = 00
  clrf  count    ;counter = 0
  clrf  delerr    ;init penalty time
  movlw  h'0e'    ;init portb                                   \
  movwf  portb    ;00001110 to explore keyboard/
  movlw  d'60'    ;60 wdt time out = 2minutes.\
  movwf  toc    ;init time out count                /
sl  bcf  intcon,0    ;re-clear flag wake-up
  movfw  portb    ;read portb (to update buffer in)
  sleep      ;waiting action on keyboard. . .
awake  btfss  status,4    ;/TO = 1 ? time out
  goto  TOCOUNT    ;/TO = 0 yes count and return sl
Main  clrwdt      ;No wake-up bye Rb4-7 change
  delays  3    ;15 millisec. débounce
  call  ANAL    ;analyze KB. Fcod = code of the key
  movfw  fcode    ;anti parasite:
  andlw  h'f0'    ;if no touch  depressed         }
  btfsc  status,z    ;the awake was caused bye }
  goto  Init2    ;a noise. Not an error.          }
  movlw  h'8A'    ;*# code
  xorwf  fcode,w    ;comparison
  btfsc  status,z    ;are the keys *# ? Cancel pswd1
  goto  ZERO    ;yes cancel pswd1, if no, verif pwd
  movlw  h'88'    ;code of the char.#
  xorwf  fcode,w    ;is it a #?
  btfsc  status,z    ;skip if not #
  goto  Lecpws    ;yes look for pwd null
  goto  firstch    ;treatment 1er char.
Lecpws  call  REPROM    ;read address 0 (length of pwd1)
  btfsc  status,z    ;eeprom 0 = 0?
  goto  Pwnull    ;yes
  call  MI    ;beap note E
  goto  FAULT    ;1st char. = # and no pwd null
Pwnull  call  MI    ;
  call  PO1R00
  goto  Faire    ;Go to choose function
firstch  movlw  fpsw
  movwf  fsr    ;for indirect addressing
  movlw  h'82'    ;*
  xorwf  fcode,w    ;is the * key ?
  btfsc  status,z
  goto  FAULT    ;* forbidden in head of pwd
  movfw  fcode
  movwf  indf    ;register 1st char. at 0x20
  call  MI
nextch  call  POR00    ;next character
  incf  fsr,f    ;increment offset
  btfsc  fsr,4    ;control out of range
  goto  FAULT    ;out of boundary
  call  PO1RN0    ;wait next touch
  call  ANAL
  call  MI
  movlw  h'88'    ;code #
  xorwf  fcode,w    ;is it # ?
  btfsc  status,z    ;skip if not #
  goto  Pwdver    ;yes # end of pwd
  movfw  fcode    ;no
  movwf  indf    ;save 2nd, 3rd, 4th, etc. char.
  goto  nextch    ;continue until # is entered
Pwdver  call  POR00
  movfw  fsr    ;Nb. of char. entered
  andlw  h'0f'
  movwf  pwlong    ;pwd length
  movwf  svpwlin    ;save pwdlong input
  clrf  eeadr    ;add. eeprom = 0
  clrf  pswdok
  call  REPROM    ;read Pwd1 length
  xorwf  pwlong,w
  btfsc  status,z    ;is it of equal length ?
  call  PWCOMP    ;yes
  movfw  svpwlin    ;pwlong destructed bye pwcomp
  movwf  pwlong    ;restore pwlong
  btfsc  pswdok,0    ;is this pwd correct ?
  goto  Faire    ;yes
  goto  FAULT    ;secret code not correct
PWCOMP  movlw  fpsw    ;refresh indirect
  movwf  fsr    ;add. 1st char.
next  incf  eeadr,f    ;eeadr = add. 1st char of pwd
  call  REPROM    ;of equal length
  xorwf  indf,w    ;compare pwd char. bye char.
  btfss  status,z    ;skip if =
  goto  Retour    ;not =
  incf  fsr,f    ;=
  decfsz  pwlong,f    ;-1
  goto  next
  incf  pswdok,f    ;set flag password Ok
Retour  movlw  h'f0'
  andwf  eeadr,f    ;clear eeadr lower (bits 0-3)
  return
Faire  call  DO    ;good code. What to do?
  call  PO1RN0    ;wait function touch
  call  ANAL    ;fcode 12,14,18,22,24,28,42,44
  call  MI
  call  PO1R00
  movlw  h'18'    ;no code of touch 3
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 3 ? /
  goto  OUV3    ;yes excit relais n°3
  movlw  h'44'    ;no code of touch 8
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 8 ? /
  goto  OUV8    ;yes excit relais n°3 for 5 sec.
  movlw  h'22'    ;no code of touch 4
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 4 ? /
  goto  PWMOD    ;yes modifie secret code
  movlw  h'24'    ;code of touch 5
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 5 ? /
  bsf  sound,0    ;yes sound = 1 (mute)
  movlw  h'28'    ;code of touch 6
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 6 ? /
  clrf  sound    ;yes sound = 0 (sound enable)
  movlw  h'42'    ;7 surprise! Try it.
  xorwf  fcode,w    ;compare      \
  btfsc  status,z    ;is touch 7 ? /
  goto  boudin    ;yes
EndMain  goto  Init2    ;nothing to do return to sleep!!

DELAY  nop      ;[\ 5 cycles of 4 microsec.
  nop      ;[\ = 20 microsec.
  incfsz  count,f    ;[/ x 256=5120 microsec.
  goto  DELAY    ;[/
  decfsz  del,f    ;delay = 5120 x del.(2 units of
  goto  DELAY    ;del equal ebout 10 millisecondes).
  return

ANAL  clrf  fcode    ;keyboard analysis
  bcf  portb,2    ;column 2 = 0
  bcf  portb,3    ;col.3 = 0. columns kb. = 100
  call  FILTRE    ;
  bcf  portb,1    ;col.1 = 0
  bsf  portb,2    ;columns keyboard = 010
  call  FILTRE
  bcf  portb,2
  bsf  portb,3    ;coloumns keyboard = 001
  call  FILTRE
  movlw  h'0e'    ;
  movwf  portb    ;restore portb explore (111)
  return
FILTRE  movfw  portb
  andlw  h'f0'    ;pick up bits 4-7
  btfsc  status,z    ;0 or not 0 ?
  return      ;= 0
  movfw  portb    ;<> 0 : pick up code
  iorwf  fcode,f    ;register the code (maybe multiple
  return      ;touch)

ZERO  call  MI
  btfss  porta,4    ;is the strap in place?
  goto  FAULT    ;no err + 1
  call  PO1R00
  clrf  eeadr    ;address EEPROM = 0
  clrf  eedata    ;length = 0
  call  WEPROM    ;write one char. in eeprom
  call  SSOL    ;beap Note G -1
  call  DO    ;ok pswd No 1 = Null. Note C.
  goto  Init2    ;finish

;     password Modification: Enter current pwd1 , #, 4, new pwd,
;     #,Number pwd 1 to 4.  ( only accessible bye Pwd1 )
PWMOD  movf  eeadr,f    ;is eeadr = 0 ? (pwd1)
  btfss  status,z    ;
  goto  FAULT    ;no it is not the master.
  movlw  fpsw    ;yes w = 0x20
  movwf  fsr    ;for indirect addressing
cont  call  POR00
  call  PO1RN0    ;entering new secret code
  call  ANAL
  call  MI
  movlw  h'88'    ;code #
  xorwf  fcode,w    ;compare
  btfsc  status,z    ;is the char. # ?
  goto  suite    ;yes
  movfw  fcode    ;no
  movwf  indf    ;register nth char.in nth fpsw
  incf  fsr,f    ;+1 indirect address
  btfsc  fsr,4    ;15 char.maxi. out off range ?
  goto  ERRBIP    ;not more than 15 char.
  goto  cont    ;next character
suite  call  POR00    ;the secret code will be changed
        ;only if the final # is typed. In
        ;case of type error wait 2 sec.
        ;and restart at the old pwd
  movfw  fsr
  andlw  h'0f'    ;w = Nb. of char. typed
  movwf  pwlong    ;pwlong = Nb. of char.
  movwf  eedata    ;eedata = secret code length
  clrf  eeadr
  call  PO1RN0    ;waiting No pwd (1à4)
  call  ANAL    ;fcode = No pwd
  call  MI
  movlw  h'12'    ;1 add.eeadr = 0
  xorwf  fcode,w    ;fcode = 1 ?
  btfsc  status,z    ;
  goto  Ecrit    ;yes goto write
  goto  ERRBIP    ;No 1, nor 2, nor 3, nor 4
Ecrit  call  PO1R00    ;write
  call  WEPROM    ;Write pwd length at 0,16,32 or 48
  movf  pwlong,f    ;to see if pwlong = 0 !
  btfsc  status,z    ;is pwlong = 0 ?
  goto  Term    ;yes pswd null ok terminate
  movlw  fpsw    ;refresh indirect add.
  movwf  fsr    ;fsr = 0x20
Suivant  clrwdt      ;next
  incf  eeadr,f    ;+ 1
  movfw  indf
  movwf  eedata
  call  WEPROM    ;write.the char.of new code
  call  SOL    ;char. Writed. Notes G E
  call  MI    ;2 tones for each char.writed
  delays  d'30'
  incf  fsr,f
  decfsz  pwlong,f
  goto  Suivant
Term  call  DO    ;Note C
  goto  Init2    ;end writing password in eeprom

WEPROM  clrwdt      ;write one char. in EEPROM
  bsf  status,5    ;bank1
  bcf  intcon,7    ;disable interrupt
  bcf  eecon1,3    ;reset write error
  bsf  eecon1,2    ;enable write (wren)
  movlw  h'55'    ;needed sequence for sécurity
  movwf  eecon2    ;   "          "
  movlw  h'aa'    ;   "          "
  movwf  eecon2    ;   "          "
  bsf  eecon1,1    ;set wr bit
  bcf  eecon1,2    ;reset wren
wait  btfss  eecon1,4    ;is write complete bit set?
  goto  wait    ;no
  bcf  eecon1,4    ;yes we reset it
  bcf  status,5    ;bank0
  return

REPROM  bsf  status,5    ;bank1 Read one char. from EEPROM
  bsf  eecon1,0    ;initiate read
  bcf  status,5    ;bank0
  movfw  eedata    ;w = char.readed
  return

SSOL  movlw  d'204'    ;G deep complement to 256 = 52
  movwf  freq    ;frequency of the beap
  movlw  d'192'    ;comp. = 64: number of pulses
  movwf  long    ;(execution time of the beap)
  goto  bip    ;emmitting beap
DO  movlw  d'217'    ;C idem for other notes
  movwf  freq    ;39 iterations for 1/2 pulse
  movlw  d'170'    ;compl. à 256 = 86
  movwf  long
  goto  bip
MI  movlw  d'225'    ;E
  movwf  freq    ;31 iterations
  movlw  d'149'    ;comp. = 107
  movwf  long
  goto  bip
SOL  movlw  d'230'    ;sol shrill G
  movwf  freq    ;26 iter.
  movlw  d'128'    ;comp. = 128
  movwf  long
bip  btfsc  sound,0    ;execution or not
  return      ;no beap if sound <> 0
          bsf  porta,0    ;load capacity 80 millisec.
  delays  d'16'    ;16 time 5,12 millisec. = 82
  bcf  porta,0    ;stop load
  movfw  freq    ;w = freq.
bipx  movwf  count    ;restore frequency
  bsf  porta,1    ;rise pulse ra1 = 1: Positive part
plus1  incfsz  count,f    ;[\ 12 microsec.
  goto  plus1    ;[/ x count (52,39,31,26)
  movwf  count    ;restore freq.
  bcf  porta,1    ;down pulse ra1 = 0: Negative part
plus2  incfsz  count,f    ;idem with ra1 = 0
  goto  plus2    ;for one pulse
  incfsz  long,f    ;we need a few
  goto  bipx    ;(64,86,107,128)
  return      ;for beap time = 80millisec.

ERRBIP  call  MI    ;E E E G   ? error beaps
  call  MI
  call  MI
  call  SOL
FAULT  call  PO1R00    ;the 1st error initialyse
  movfw  err    ;err to 252
  sublw  d'252'
  btfss  status,0    ;is err < 252? (test carry)
  goto  plus    ;no err >= 252
  movlw  d'252'    ;yes restor to 252\
  movwf  err    ;init err                 /
plus  incfsz  err,f    ;+1 = 4 errors ?
  goto  Init2    ;no return to sleep
penalty  clrwdt      ;yes
  delays  d'92'    ;0,47 sec.
  incfsz  delerr,f    ;0,47 x 256 = 2min.
  goto  penalty    ;wait
  movlw  d'252'    ;init Nb. permit \
  movwf  err    ;errors to 4       /
  goto  Init2    ;penalty terminated: sleep

POR1N0  movfw  portb    ;wait depressing one key
  andlw  h'f0'    ;select bits 4-7
  btfsc  status,z    ;
  goto  POR1N0    ;portb empty : read portb again
  clrwdt      ;portb received a char.
  delays  3    ;15 msec. débounce
  return

POR100  movfw  portb    ;wait releasing key
  andlw  h'f0'    ;bits 4-7
  btfss  status,z
  goto  POR00    ;portb not empty read portb again
  clrwdt      ;portb empty
  delays  4    ;20 msec. débounce
  return

TOCOUNT  ;awake from sleep bye time out wdt: cancel Nb. Of err.
  ;if continusly sleep for 2 min. without key depressed.
  decfsz  toc,f    ;-1 time out count
  goto  sl    ;return to sleep
  movlw  d'252'    ;cancel Nb. Of errors
  movwf  err    ;init to 252 (4errors)
  goto  Init2

OUV3  bsf  porta,2    ;excit relais 3 for trigger
  goto  mus
OUV8  bsf  porta,2    ;excit relais 3 trigger for 5 sec.
  delays  d'200'
  clrwdt
  delays  d'200'    ;ebout 1 sec.
  clrwdt
  delays  d'200'
  clrwdt
  delays  d'200'
mus  clrwdt      ;excit relais for 2 secondes.
  delays  30
  call  DO    ;C g C G E
  call  SSOL    ;Good termination of procedure
  call  DO
  call  SOL
  call  MI
boucle  goto  boucle    ;ending bye wdt time out(2sec.)

boudin
  delays  d'128'    ;
  call  boudin0    ;No comment
  call  boudin5
  call  boudin5
  call  boudin0
  clrwdt
  call  SSOL    ;Ssol = G-1
  call  DO    ;Do = C; Mi = E; sol = G
  delays  d'96'    ;No comment
  call  MI
  delays  d'96'
  call  DO
  goto  Init2
boudin5  call  boudin4
  clrwdt
  delays  d'64'
  call  SSOL
  call  DO
  delays  d'32'
  call  MI
  delays  d'32'
  clrwdt
  call  SOL
  delays  d'96'
  call  MI
  delays  d'96'
  call  boudin4
  call  SSOL
  call  DO
  call  MI
  call  SOL
  delays  d'32'
  call  SSOL
  delays  d'32'
  clrwdt
  call  DO
  delays  d'224'
  return
boudin0  call  boudin1
  call  boudin1
  call  boudin1
  clrwdt
  call  DO
  delays  d'224'
  call  boudin2
  call  boudin2
  call  boudin2
  call  DO
  delays  d'32'
  call  MI
  delays  d'32'
  clrwdt
  call  DO
  delays  d'96'
  call  DO
  delays  d'96'
  clrwdt
  call  SSOL
  delays  d'32'
  call  DO
  delays  d'32'
  call  SSOL
  call  boudin3
  call  MI
  delays  d'32'
  call  SOL
  call  boudin3
  delays  d'192'
  return
boudin1  clrwdt
  call  DO
  delays  d'96'
  call  DO
  call  SSOL
  call  DO
  call  MI
  return
boudin2  clrwdt
  call  DO
  delays  d'32'
  call  SSOL
  delays  d'32'
  return
boudin3  clrwdt
  delays  d'32'
  call  DO
  call  DO
  call  DO
  delays  d'32'
  call  SSOL
  call  SSOL
  call  SSOL
  clrwdt
  delays  d'32'
  call  MI
  call  MI
  call  MI
  delays  d'32'
  call  DO
  call  DO
  call  DO
  clrwdt
  delays  d'96'
  call  SSOL
  clrwdt
  delays  d'32'
  call  SSOL
  call  SSOL
  call  SSOL
  clrwdt
  delays  d'32'
  call  SSOL
  delays  d'32'
  call  DO
  delays  d'32'
  return
boudin4  clrwdt
  call  DO
  call  DO
  call  DO
  call  DO
  call  DO
  delays  d'32'
  call  MI
  delays  d'32'
  clrwdt
  call  SSOL
  call  SSOL
  call  SSOL
  call  SSOL
  call  SSOL
  delays  d'32'
  call  MI
  delays  d'32'
  call  DO
  clrwdt
  return
  end      ;It's good like that.

von Hasan S. (hasansivan)


Lesenswert?

schau mal in der routine faire da springt der pic wenn die taste 7 
gedrückt wird nach boudin.

von Chris B. (dekatz)


Lesenswert?

Der Ton wird mit der Routine "bip" erzeugt.
Wozu diese 80ms dienen ist mir nicht klar (ohne Schaltplan was 
eigentlich an PortA.0 hängt).

bip  btfsc  sound,0    ;execution or not
     return            ;no beap if sound <> 0
     bsf  porta,0     ;load capacity 80 millisec.
     delays  d'16'    ;16 time 5,12 millisec. = 82
     bcf  porta,0     ;stop load
Los geht es danach:
Um 784Hz für ein G5 zu erzeugen werden in der Routine "SSOL" die 
Variablen
<freq> mit 204 geladen. Die Differenz 52 auf 256 ist die Dauer mit der 
die Portleitung  für die Tonerzeugung jeweils!! auf HIGH und dann auf 
LOW geht.

Die eigentliche Frequenzerzeugung läuft hier:
1. Der Startwert <freq> wird in <count> geladen, die Tonausgabe auf HIGH 
gesetzt und <count> solange hochgezählt bis ein Überlauf auf 0x00 
erfolgt.
52 Schleifendurchläufe * 12µs = 624µs - sol lange dauert der HIGH-Teil 
des Ton.

      movfw  freq     ;w = freq.
bipx  movwf  count    ;restore frequency
      bsf  porta,1    ;rise pulse ra1 = 1: Positive part
plus1
      incfsz  count,f  ;[\ 12 microsec.
      goto  plus1      ;[/ x count (52,39,31,26)

2. Der Startwert <freq> wird in <count> geladen, die Tonausgabe auf LOW 
gesetzt und <count> solange hochgezählt bis ein Überlauf auf 0x00 
erfolgt. 52 Schleifendurchläufe * 12µs = 624µs - sol lange dauert der 
LOW-Teil des Ton.

      (*) hier fehlt offensichtlich ein "movfw  freq" !?!?
      movwf  count    ;restore freq.
      bcf  porta,1    ;down pulse ra1 = 0: Negative part
plus2
      incfsz  count,f    ;idem with ra1 = 0
      goto  plus2        ;for one pulse

3. Macht in Summ 2 * 624µs = 1248µs plus das Laden des Zählers und 
Schleifensteuerung für die Tonlänge nochmal 24µs ...macht 1272µs = 
0,001272s, daraus die Frequenz 1/t = 786,16...Hz

4. Das ganze wir solange wiederholt wie für die Dauer des Ton vorgesehen 
ist.
      incfsz  long,f    ;we need a few
      goto  bipx        ;(64,86,107,128)
      return            ;for beap time = 80millisec.

Mit einem RC-Oszillator und dieser Schleifenkonstruktion mit 12µs 
Auflösung lassen sich natürlich keine genauen Frequenzen erzeugen!!!
Aber mit der Info kannst du dann auch fast jeden anderen Ton 
erzeugen.....

von Hasan S. (hasansivan)


Lesenswert?

Danke für die Informative Information.
Wie kommt man auf die 12 uS ??

von Chris B. (dekatz)


Lesenswert?

Der Oszillator läuft mit 1MHz also ist Tosc = 1µs.
Ein Befehlszyklus umfasst 4 * Tosc = 4µs.
Die Schleife besteht im wesentlichen nur aus INCFZ und GOTO.
INCFSZ benötigt 1 und das GOTO benötigt 2 Befehlszyklen - also 3 * 4µs.

von Hasan S. (hasansivan)


Lesenswert?

Chris B. schrieb:
> Der Oszillator läuft mit 1MHz also ist Tosc = 1µs.
> Ein Befehlszyklus umfasst 4 * Tosc = 4µs.
> Die Schleife besteht im wesentlichen nur aus INCFZ und GOTO.
> INCFSZ benötigt 1 und das GOTO benötigt 2 Befehlszyklen - also 3 * 4µs.


Danke, jetzt verstehe ich es jedoch ist doch eine Frage hier wird ein 
Makro für die Wartschleife verwendet die Warteschleife beträgt 5120uS. 
Woher kommen diese 5120 uS ??

von Chris B. (dekatz)


Lesenswert?

Das steht im DELAY beschrieben: NOP + NOP + INCFSZ + GOTO benötigt 5 
Befehlszyklen a 4µs = 20µs * 256 (Variable <count> wird von 0x00 
hochegezählt bis sie überläuft) = 5120µs

von Hasan S. (hasansivan)


Lesenswert?

Stimmt ja ,danke Trotzdem. Ich hab noch eine bitte bei dieser Schleife 
wo man die Taste 4 drück um den Passwort zu ändern, was wird genau 
gemacht ? Entschuldige für die Unannehmlichkeit  :

;     password Modification: Enter current pwd1 , #, 4, new pwd,
;     #,Number pwd 1 to 4.  ( only accessible bye Pwd1 )
PWMOD  movf  eeadr,f    ;is eeadr = 0 ? (pwd1)
  btfss  status,z    ;
  goto  FAULT    ;no it is not the master.
  movlw  fpsw    ;yes w = 0x20
  movwf  fsr    ;for indirect addressing
cont  call  POR00
  call  POR1N0    ;entering new secret code
  call  ANAL
  call  MI
  movlw  h'88'    ;code #
  xorwf  fcode,w    ;compare
  btfsc  status,z    ;is the char. # ?
  goto  suite    ;yes
  movfw  fcode    ;no
  movwf  indf    ;register nth char.in nth fpsw
  incf  fsr,f    ;+1 indirect address
  btfsc  fsr,4    ;15 char.maxi. out off range ?
  goto  ERRBIP    ;not more than 15 char.
  goto  cont    ;next character
suite  call  POR00    ;the secret code will be changed
        ;only if the final # is typed. In
        ;case of type error wait 2 sec.
        ;and restart at the old pwd
  movfw  fsr
  andlw  h'0f'    ;w = Nb. of char. typed
  movwf  pwlong    ;pwlong = Nb. of char.
  movwf  eedata    ;eedata = secret code length
  clrf  eeadr
  call  POR1N0    ;waiting No pwd (1à4)
  call  ANAL    ;fcode = No pwd
  call  MI
  movlw  h'12'    ;1 add.eeadr = 0
  xorwf  fcode,w    ;fcode = 1 ?
  btfsc  status,z    ;
  goto  Ecrit    ;yes goto write
  goto  ERRBIP    ;No 1, nor 2, nor 3, nor 4
Ecrit  call  POR00    ;write
  call  WEPROM    ;Write pwd length at 0,16,32 or 48
  movf  pwlong,f    ;to see if pwlong = 0 !
  btfsc  status,z    ;is pwlong = 0 ?
  goto  Term    ;yes pswd null ok terminate
  movlw  fpsw    ;refresh indirect add.
  movwf  fsr    ;fsr = 0x20
Suivant  clrwdt      ;next
  incf  eeadr,f    ;+ 1
  movfw  indf
  movwf  eedata
  call  WEPROM    ;write.the char.of new code
  call  SOL    ;char. Writed. Notes G E
  call  MI    ;2 tones for each char.writed
  delays  d'30'
  incf  fsr,f
  decfsz  pwlong,f
  goto  Suivant
Term  call  DO    ;Note C
  goto  Init2    ;end writing password in eeprom

WEPROM  clrwdt      ;write one char. in EEPROM
  bsf  status,5    ;bank1
  bcf  intcon,7    ;disable interrupt
  bcf  eecon1,3    ;reset write error
  bsf  eecon1,2    ;enable write (wren)
  movlw  h'55'    ;needed sequence for sécurity
  movwf  eecon2    ;   "          "
  movlw  h'aa'    ;   "          "
  movwf  eecon2    ;   "          "
  bsf  eecon1,1    ;set wr bit
  bcf  eecon1,2    ;reset wren
wait  btfss  eecon1,4    ;is write complete bit set?
  goto  wait    ;no
  bcf  eecon1,4    ;yes we reset it
  bcf  status,5    ;bank0
  return

REPROM  bsf  status,5    ;bank1 Read one char. from EEPROM
  bsf  eecon1,0    ;initiate read
  bcf  status,5    ;bank0
  movfw  eedata    ;w = char.readed
  return


POR1N0
  movfw  portb    ;warte auf Tasterbestätigung
  andlw  h'f0'    ;wähle bits 4-7
  btfsc  status,z    ;
  goto  POR1N0    ;portb leer , wiederhole PortB lese
  clrwdt
  delays  3    ;15 msec. Entprellung
  return

POR00
  movfw  portb    ;warte auf Tasterbestätigung
  andlw  h'f0'    ;wähle bits 4-7
  btfss  status,z
  goto  POR00    ;portb nicht leer lese wieder portb
  clrwdt
  delays  4        ;20 msec. Entprellung
  return

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.