Jump to content
ELFORUM - Forumul electronistilor

Modificare cod pt 12f675 in 16f628a


Recommended Posts

Salut

Am urmatorul cod in mikrobasic pt 12f675.

Doresc sa ma ajutati in modificarea respectivului cod pt a putea folosi pe un 16f628A. (nu reusesc sa ma descurc cu partea de intreruperi...)

Codul este urmatorul:

program testsymbol LED     = GPIO.5 const led_tmr= 10dim inter_cnt as bytesub procedure Init_Main()' Osccal restore  OSCCAL=OSCCAL  asm     BSF     STATUS,RP0    ; set file register bank to 1     CALL    0x3FF         ; retrieve factory calibration value     MOVWF   OSCCAL        ; update register with factory cal value     BCF     STATUS,RP0    ; set file register bank to 0  end asm  CMCON=7  ANSEL=0  GPIO=0  TRISIO=%001111  T0CS_bit=0               ' internal clock source for TMR0  PSA_bit=0                ' prescale assigned to TMR0  PS2_bit=1                ' 1:256 prescaler to TMR0  PS1_bit=1  PS0_bit=1  T0IE_bit=1               ' enable TMR0 interrupt  GIE_bit=1                ' enable  interruptsend subsub procedure interrupt    TMR0=61                 ' preload timer  ( ~50 ms overflow period)    Inc(inter_cnt)      ' increment interrupts counter    if inter_cnt=led_tmr then       inter_cnt=0      ' reset interrupts counter       LED=not(LED)     ' toggle LED    end if    T0IF_bit=0          ' reset flagend submain:'   Main program   Init_Main()  inter_cnt=0              ' initialize counterwhile TRUE   ' restul programului.....wendend.

Va multumesc anticipat.

Link to comment
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

program test

'symbol LED = GPIO.5

symbol LED = PORTA.5

const led_tmr= 10

dim inter_cnt as byte

 

sub procedure Init_Main()

' Osccal restore

' OSCCAL=OSCCAL

' asm

' BSF STATUS,RP0 ; set file register bank to 1

' CALL 0x3FF ; retrieve factory calibration value

' MOVWF OSCCAL ; update register with factory cal value

' BCF STATUS,RP0 ; set file register bank to 0

' end asm

CMCON=7

 

'ANSEL=0

VRCON = 0

' GPIO=0

PORTA = 0

'TRISIO=%001111

TRISA = %0000111 ; fac din porta.5 iesire

T0CS_bit=0 ' internal clock source for TMR0

PSA_bit=0 ' prescale assigned to TMR0

PS2_bit=1 ' 1:256 prescaler to TMR0

PS1_bit=1

PS0_bit=1

T0IE_bit=1 ' enable TMR0 interrupt

GIE_bit=1 ' enable interrupts

end sub

 

sub procedure interrupt

TMR0=61 ' preload timer ( ~50 ms overflow period)

Inc(inter_cnt) ' increment interrupts counter

if inter_cnt=led_tmr then

inter_cnt=0 ' reset interrupts counter

LED=not(LED) ' toggle LED

end if

T0IF_bit=0 ' reset flag

end sub

 

main:

' Main program

Init_Main()

inter_cnt=0 ' initialize counter

while TRUE

' restul programului.....

wend

end.

Link to comment

Poate te ajuta acest exemplu, desi este scris in PicBasicPro :

@ DEVICE pic16F628A, intOSC_osc_noclkout, WDT_OFF, PWRT_ON, MCLR_OFF, LVP_OFF, CPD_OFFDEFINE OSC 4CMCON	= 7VRCON 	= 0INTCON 	= 0	TrisB=0					' Make PortB outputs	TrisA.0=0:TrisA.1=0:TrisA.2=0		' Make only the specific bits of PortA outputs						TrisA.3=0:TrisA.4=1	PortA=0:PortB=0			     	' Clear PortB and PortAINTCON = %00100000OPTION_REG = %10000000ON INTERRUPT GOTO ISRINTCON = %10100000MAIN : ; aici e codul principalGoto MainDISABLEISR:   ; aici se pune ceea ce doreste a se face in intrerupereINTCON.2=0RESUMEENABLE
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines