program

Rasprava o PIC mikrokontrolerima, PIC projekti i drugo vezano za PIC-eve...

Moderators: pedja089, stojke369, [eDo], trax

Post Reply
User avatar
UNWANTED
Pravo sam se raspisao :)
Pravo sam se raspisao :)
Posts: 1251
Joined: 21-12-2005, 17:43
Location: hrvatska
Contact:

program

Post by UNWANTED »

kako ovo upisati kojim progijem upisati
Program 1:
Očitavanje TUCH Memorija AVR-ovim čipom 1200
;*Includes*
.include "1200def.inc"

;* Pin Definitions*

.equ RxD =6
.equ TxD =0
.equ LED =2

;*Global Register Variables*

.def greska =r16
.def temp1 =r17
.def temp2 =r18
.def temp3 =r19
.def acca =r20
.def accb =r21
.def ZL =r30
.def ZH =r31

;* Interrupt Vectors*

rjmp RESET

;*************
;* FUNCTION
;*
;* w30us (1+(1+2)*79+4=242=30.25us)
;*************

w30us:
ldi temp1,79 ;1~
tloop1: dec temp1 ;1~
brne tloop1 ;2~ 1+(1+2)*79+4=242=30.25us
ret ;4~

;*************
;* FUNCTION
;*
;* w5us
;*************

w5us:
ldi temp1,12 ;1~
tloop2: dec temp1 ;1~
brne tloop2 ;2~ 1+(1+2)*13+4=242=5.5us
ret ;4~

;*************
;* FUNCTION
;*
;* w480us
;*************

w480us:
ldi temp1,0x5
tl13: ldi temp2,0xff
tl12: dec temp2
brne tl12
dec temp1
brne tl13
ret

;*************
;* FUNCTION
;*
;* w300us
;*************

w300us:
ldi temp1,0x4
tl23: ldi temp2,0xff
tl22: dec temp2
brne tl22
dec temp1
brne tl23
ret

;*************
;* FUNCTION
;*
;* w200ms
;*************

w200ms: ldi temp3, 16 ;1~
tl3: ldi temp2, 0x82 ;1~
tl2: ldi temp1, 0xff ;1~
tl1: dec temp1 ;1~
brne tl1 ;2~
dec temp2 ;1~
brne tl2 ;2~
dec temp3 ;1~
brne tl3 ;2~
ret ;4~

;*************
;* FUNCTION
;*
;* test
;*************

test: sbi PORTD,0 ; Tx =1
rcall w480us
cbi PORTD,0 ; Tx =0
rcall w30us
rcall w30us
rcall ima
ret

;*************
;* FUNCTION
;*
;* ima
;*************

ima: in acca,pind
andi acca,0x40
brne l2
ldi greska,0x02
l2: rcall w480us
ret

;*************
;* FUNCTION
;*
;* citanje
;*************

citanje:
rcall w_one
rcall w_one
rcall w_zero
rcall w_zero
rcall w_one
rcall w_one
rcall w_zero
rcall w_zero
ret

;*************
;* FUNCTION
;*
;* w_one
;*************
w_one:
sbi portd,TxD
rcall w5us
cbi portd,TxD
rcall w60us

ret

;*************
;* FUNCTION
;*
;* w_zero
;*************
w_zero:
sbi portd,TxD
rcall w60us


cbi portd,TxD
rcall w5us
ret

;*********************************
;* FUNCTION
;*
;* w60us (1+(1+2)*160+4=125~=60.62us
;*********************************
w60us:
ldi temp1,160 ;1~
tl4: dec temp1 ;1~
brne tl4 ;2~
ret ;4~
;*********************************
;* FUNCTION
;*
;* read_no
;*********************************
read_no:
clr ZH
ldi ZL,0x08
rl2: dec ZL
ldi temp3,0x08
clr acca
rl1: asr acca
andi acca,0x7f
sbi portd,TxD
nop
nop
nop
nop
cbi portd,TxD
rcall w5us
in accb,pind
lsl accb
andi accb,0x80
rcall w60us
add acca,accb
dec temp3
brne rl1
st Z,acca
cpi ZL,0x00
brne rl2
ret

;*************
;* FUNCTION
;*
;* r_bit
;*************

EERead_seq:
in temp1,EEAR ;get address
inc temp1 ;increment address
out EEAR,temp1 ;output address
sbi EECR,EERE ;set EEPROM Read strobe
;This instruction takes 4 clock cycles since
;it halts the CPU for two clock cycles
sbi EECR,EERE ;set EEPROM Read strobe 2nd time
;This instruction takes 4 clock cycles since
;it halts the CPU for two clock cycles
in temp2,EEDR ;get data
ret



;***** Copy 8 bytes of EEPROM to registers
copy:

out EEAR,accb ;EEAR <- $ff (start address - 1)
ldi ZL,8 ;Z-pointer points to r8
loop2: rcall EERead_seq ;get EEPROM data
st Z,temp2 ;store to SRAM
inc ZL
cpi ZL,16 ;reached the end?
brne loop2 ;if not, loop more
ret

;*************
;* FUNCTION
;*
;* provera
;*************
provera:
ldi temp3,0x08
mov acca,r0
mov accb,r8
rcall lp1
mov acca,r1
mov accb,r9
rcall lp1
mov acca,r2
mov accb,r10
rcall lp1
mov acca,r3
mov accb,r11
rcall lp1
mov acca,r4
mov accb,r12
rcall lp1
mov acca,r5
mov accb,r13
rcall lp1
mov acca,r6
mov accb,r14
rcall lp1
mov acca,r7
mov accb,r15
rcall lp1
ret

lp1: cpse acca,accb
ret
dec temp3
breq lp2
lp3: ret

lp2: ldi greska,0x08
rjmp lp3

;*********************************
; beep Tonski signal, LED i rele
;*********************************
beep:
sbi portd,LED
ldi acca,0x07
bl2: ldi temp3,0xff
bl1: sbi portd,1
rcall w300us
cbi portd,1
rcall w300us
dec temp3
brne bl1
dec acca
brne bl2
clr greska
cbi portd,LED
ret

RESET:

main:
clr greska
ldi temp1,0xff
out ddrb,temp1
sbi DDRD,2
sbi DDRD,1
sbi DDRD,0
l6: rcall test
andi greska,0x02
breq l6
rcall citanje
rcall read_no
ldi accb,0xff
rcall copy
rcall provera
andi greska,0x08
breq ll1
rcall beep
ll1: ldi accb,0x07
rcall copy
rcall provera
andi greska,0x08
breq ll2
rcall beep
ll2: rjmp main


zer0
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 250
Joined: 05-08-2005, 21:10

Post by zer0 »

AVR Studio 4, potrazi na
www.atmel.com
User avatar
UNWANTED
Pravo sam se raspisao :)
Pravo sam se raspisao :)
Posts: 1251
Joined: 21-12-2005, 17:43
Location: hrvatska
Contact:

Post by UNWANTED »

hvala! :)
buco

Post by buco »

Taj "source" je dobiven generickim programiranjem bar po nekim rijesenjima koje se vide , npr u read_no rutini... !?
User avatar
UNWANTED
Pravo sam se raspisao :)
Pravo sam se raspisao :)
Posts: 1251
Joined: 21-12-2005, 17:43
Location: hrvatska
Contact:

Post by UNWANTED »

ok!sta to znaci posto se ja ne kuzim samo znam da to moram napucati u chip i to u roku od 2-3 tjedna a neznam ni koju shemu za programator napraviti
User avatar
stojke369
Administrator sajta
Administrator sajta
Posts: 3913
Joined: 19-10-2005, 01:41
Location: Srbija-Paracin

Post by stojke369 »

ok!sta to znaci posto se ja ne kuzim samo znam da to moram napucati u chip i to u roku od 2-3 tjedna a neznam ni koju shemu za programator napraviti
:D :D :D


To je strucnost :wink:
buco

Post by buco »

generiran izvorni kod nekim od crosscompilera iz visih prog jezika , znaci nije pisan izvorno u assembleru !
Posto mu ne treba 12V imas ICprog ili pony programtor preko paralelnog porta . Oko 5 linija koristit i par otpornika !
Shemu samog spajanja MCU pinova imas u svakoj dokumentaciji o MCUu [ Atmel je to dobro napravio] !
Ja te stare sheme nemam vise u ovom compu , malo googlaj i naci ces 100% nesto jednostavno s otpornicima na LPTu.
Post Reply