Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PRESERVE8
- AREA MyCode,CODE,READONLY
- EXPORT config
- IMPORT my_fprint
- EXPORT asm_pit1_irq
- PIT1_IRQHandler EQU asm_pit1_irq+1
- EXPORT PIT1_IRQHandler ;the vector table must contain odd addresses for the Cortex processor
- my_SIM_SCGC5 EQU 0x40048038 ;Address for SIM_SCGC5
- my_GPIOC_clken EQU 0x00000200 ;Clock gate enable for port A
- my_PORTA_PCR11 EQU 0x4004902C ;PortA PCR 11 -> LED D7
- my_PORTA_PCR28 EQU 0x40049070
- my_PORTA_PCR29 EQU 0x40049074
- PORTA_PCR_VAL EQU 0x00000140
- my_GPIOA_PDOR EQU 0x400FF000
- GPIOA_PDOR_VAL EQU 0x30000800
- my_GPIOA_PCOR EQU 0x400FF008
- my_GPIOA_PSOR EQU 0x400FF004
- my_SIM_SCGC6 EQU 0x4004803C
- my_SCGC6_value EQU 0x00800000
- my_PIT_MCR EQU 0x40037000
- my_PIT_LDVAL1 EQU 0x40037110
- my_LDVAL1_value EQU 0x05F5E0FF
- my_PIT_TFLG1 EQU 0x4003711C
- my_PIT_TCTRL1 EQU 0x40037118
- my_NVIC_addr EQU 0xE000E108
- my_NVIC_value EQU 0x00000020
- config
- ;write 1 to bit {9} of SIM_SCGC5, enable Port A clock gate
- LDR r2, =my_SIM_SCGC5 ;0x40048038
- LDR r1, =my_GPIOC_clken ;0x00000200
- LDR r3, [r2]
- ORR r3, r3, r1
- STR r3, [r2] ;enable GPIO_PORTA
- LDR r2, =my_PORTA_PCR11 ;0x4004902C address for orange LED
- ;For PortA PCR11, PCR28, PCR29 (3 LEDs):
- ;write 1 to bit {6}, DSE, high drive strength
- ;write 001 to bits {8-10}, MUX, alternative 1 GPIO
- LDR r1, =PORTA_PCR_VAL ;0x00000140
- STR r1, [r2] ;updates memory address to PTA28, yellow LED
- ldr r2, =my_PORTA_PCR28
- STR r1, [r2] ;updates memory address to PTA29, green LED
- ldr r2, =my_PORTA_PCR29
- STR r1, [r2]
- ;turn off/reset LEDs:
- ;set PDOR PTA bits 11, 28, 29 to logic 1
- LDR r2, =my_GPIOA_PDOR ;0x4000FF000
- LDR r1, =GPIOA_PDOR_VAL ;0x300000800
- STR r1, [r2], #20 ;updates memory addres to GPIOA_PDDR
- ;sets PDDR PTA fields 11, 28, 29 to general purpose output (1 to bits {11, 28, 29}
- STR r1, [r2]
- ;Set PIT timer by writing 1 to bit {23}
- LDR r2,=my_SIM_SCGC6 ;0x4004803C
- LDR r1,=my_SCGC6_value ;0x00800000
- LDR r0,[r2]
- ORR r0,r0,r1
- STR r0,[r2] ;enable clock to PIT1
- ;enable the PIT module (0 to bits {0-1} of the MCR)
- LDR r2,=my_PIT_MCR ;0x40037000, memory address for PCR
- MOV r0,#0
- STR r0,[r2] ;stores 0x0 into PCR
- ;sets the timer to interrupt every 2s by writing LDVAL1
- LDR r2,=my_PIT_LDVAL1 ;0x40037110, memory address for PIT_LDVAL1
- ;want it to trigger every 2s
- ;2s/20ns - 1 =100e6 - 1 =0x05F5E0FF
- LDR r1,=my_LDVAL1_value ;0x05F5E0FF
- STR r1,[r2] ;load the count value to generate interrupt periodically
- ;store 1 in bits {0,1} of TCTRL1, enable timer and interrupts
- LDR r2,=my_PIT_TCTRL1 ;0x40037118, memory address for PIT_TCTRL1
- MOV r0,#0x3
- STR r0,[r2] ;set TIE and TEN bits
- ;NVIC CONVIG
- LDR r2,=my_NVIC_value ;0x00000020 sets IRQ 69
- LDR r1,=my_NVIC_addr ;0xE000E108
- STR r2, [r1]
- loop B loop
- asm_pit1_irq
- PUSH {lr} ;store LR
- LDR r2,=my_PIT_TFLG1 ;Load memory address of TFLG1
- MOV r3,#0x01 ;1 to clear flag
- STR r3,[r2] ;store to memory to clear flags
- LDR r2, =irqcounter ;load memory address of irqcounter
- LDRB r3,[r2] ;loads value from counter into r3
- CMP r3,#1 ;if 1 turn off leds
- BEQ led_off
- ADD r3,#1 ;increment counter
- STRB r3,[r2] ;stores value of r3 into counter
- B led_on ;if 0 turn on leds
- led_off
- MOV r3,#0x00 ;reset counter (limit between 0 and 1)
- str r3, [r2]
- LDR r7, =my_GPIOA_PSOR ;memory address of PSOR
- LDR r8, =GPIOA_PDOR_VAL ;writes 1 at bits {11,28,29} to PSOR
- str r8, [r7] ;turns off LEDs
- POP {pc}
- led_on
- LDR r7, =my_GPIOA_PCOR ;memory address of PCOR
- LDR r8, =GPIOA_PDOR_VAL ;writes 1 at bits {11, 28, 29} to PCOR
- STR r8, [r7] ;turns on LEDs
- POP {pc} ;restore program
- ALIGN
- AREA MyData, DATA, READWRITE
- irqcounter DCD 0x00
- DCD
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement