Advertisement
Guest User

Untitled

a guest
Dec 4th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 2.88 KB | None | 0 0
  1. SIM_SCGC5   EQU  0x40048038 ;SIM_SCGC5 address  
  2. SIM_COPC    EQU  0x40048100 ;SIM_COPC (watchdog) address
  3.    
  4. PORTA_PCR2  EQU  0x40049008 ;PORTA_PCR2 (PTA2) address
  5. PORTA_PCR4  EQU  0x40049010 ;PORTA_PCR4 (PTA4) address
  6. PORTA_PCR5  EQU  0x40049014 ;PORTA_PCR5 (PTA5) address
  7. PORTC_PCR7  EQU  0x4004B01C ;PORTA_PCR7 (PTC7) address
  8.  
  9. PORTA_PDDR  EQU 0x400FF014
  10. PORTA_PDOR  EQU 0x400FF000
  11. PORTC_PDDR  EQU 0x400FF094
  12. PORTC_PDIR  EQU 0x400FF090
  13.    
  14. GREEN_MASK   EQU 0x00000004 ; PORTA_PIN 2
  15. YELLOW_MASK  EQU 0x00000010 ; PORTA_PIN 4
  16. RED_MASK     EQU 0x00000020 ; PORTA_PIN 5
  17. INIT_MASKS   EQU 0x00000034 ; PORTA_PIN 2, 4 and 5
  18. BUTTON_MASK  EQU 0X00000080 ; PORTC_PIN 7
  19. DELAY_CNT    EQU 0X00800000
  20.  
  21.     AREA asm_area, CODE, READONLY
  22.     EXPORT  asm_main
  23. asm_main  ;assembly entry point for C function, do not delete
  24. ; Add program code here
  25.     BL init_gpio  
  26. loop
  27.     BL greenon
  28.     LDR R0, =DELAY_CNT
  29.     BL  delay
  30.     BL  redon
  31.     LDR R0, =DELAY_CNT
  32.     BL  delay
  33.     BL  yellowon
  34.     LDR R0, =DELAY_CNT
  35.     BL  delay
  36.     B   loop
  37. greenon
  38.     LDR R0,=PORTA_PDOR  ;Load address of GPIOB_PCOR to R0
  39.     LDR R1,=GREEN_MASK    ;Load value to R1
  40.     STR R1,[R0]     ;Put value into GPIOB_PCOR
  41.     BX LR
  42.  
  43. redon
  44.     LDR R0,=PORTA_PDOR  ;Load address of GPIOB_PSORto R0
  45.     LDR R1,=RED_MASK    ;Load value to R1
  46.     STR R1,[R0]     ;Put value into GPIOB_PSOR
  47.     BX LR
  48.  
  49. yellowon
  50.     LDR R0,=PORTA_PDOR  ;Load address of GPIOD_PTOR to R0
  51.     LDR R1,=YELLOW_MASK    ;Load value to R1
  52.     STR R1,[R0] ;Put value into GPIOD_PTOR
  53.     BX LR
  54.  
  55. delay
  56.     SUBS R0, #1
  57.     BNE  delay
  58.     BX LR
  59.  
  60. init_gpio
  61.     ;Disable watchdog timer (COP)
  62.     LDR R0,=SIM_COPC
  63.     LDR R1,=0x0
  64.     STR R1,[R0]
  65.    
  66.     ;Turns on clocks for all ports
  67.     LDR R0,=SIM_SCGC5    ;Load address of SIM_SCGC5 to R0
  68.     LDR R1,[R0]          ;Get original value of SIM_SCGC5
  69.     LDR R2,=0x00003E00   ;Load mask for bits to set to R2
  70.     ORRS R1,R2           ;Set bits with OR of orig val and mask
  71.     STR R1,[R0]          ;Put new value back into SIM_SCGC5
  72.    
  73.     ; Set PORTS to appropriate MUX settings
  74.     LDR R0,=PORTA_PCR2   ;Load address of PORTA_PCR2 to R0
  75.     LDR R1,=0x01    ;Load new value to R1
  76.     STR R1,[R0]
  77.  
  78.     ; Set PORTS to appropriate MUX settings
  79.     LDR R0,=PORTA_PCR4   ;Load address of PORTA_PCR4 to R0
  80.     LDR R1,=0x01    ;Load new value to R1
  81.     STR R1,[R0]
  82.    
  83.     LDR R0,=PORTA_PCR5   ;Load address of PORTA_PCR5 to R0
  84.     LDR R1,=0x01    ;Load new value to R1
  85.     STR R1,[R0]
  86.    
  87.     LDR R0,=PORTC_PCR7   ;Load address of PORTC_PCR7 to R0
  88.     LDR R1,=0x01    ;Load new value to R1
  89.     STR R1,[R0]
  90.    
  91.     ; Setup PORTA Pins 2,4 and 5 to be outputs
  92.     LDR R0,=PORTA_PDDR   ;Load address of PORTB_PCR18 to R0
  93.     LDR R1,=INIT_MASKS    ;Load new value to R1
  94.     STR R1,[R0]           ;Put value into PORTB_PCR18
  95.  
  96.     ; Setup PORTC Pin 7 to be an input
  97.     LDR R0,=PORTC_PDDR ; Load address of PORTC_PDDR to R0
  98.     LDR R1,=BUTTON_MASK     ;Load new value to R1
  99.     STR R1,[R0]            ;Put value into PORTC_PDDR
  100.  
  101.  
  102.     BX LR
  103.  
  104.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement