#**************************************************************************************** # PIC32MX120F032B Sample Program # Project : # Program Name : # Programer : # Create date : Version 1.0 H24.06.14 # History : # Laungage : Gcc (MPLAB C32) Asm / Internal OSC : 8MHz #***************************************************************************************** # Description # (1)Memory load map # Config words : Physical(0x1FC00BF0-0x1FC00BFF)/Virtual(0xBFC00BF0-0xBFC00BFF) # RAM : Physical(0x00000000-0x00001FFF)/Virtual(0x80000000-0x80001FFF) # Program memory:Physical(0x1D000000-0x1D007FFF)/Virtual(0x9D000000-0x9D007FFF) # SFRs : Physical(0x1F800000-0x1F8FFFFF)/Virtual(0xBF800000-0xBF8FFFFF) # (2)Assembler File extension # ****.S (S:Preprocessed Source file / s:Source file) # (3)Compile Gcc(C32) # (4)general purpose register ( 32bit * 32 ) memo # $0(Fixed 0), $1(not use), $2-$3(v0-v1:return-value register), $4-$7(a0-a3:argument register) # $8-$15,$24-$25(t0-t9:free), $16-$23,$30(s0-s8:free), $26-$27(k0-k1:OS/not use), $28(gp:groval pointer) # $29(sp:stack pointer), $31(ra:return adress) # $f0, $12/13,$14/15(float type pare) #***************************************************************************************** #include # # Define config words # .section .config_1FC00BF0,code // USERID,PMDL1WAY,IOL1WAY,FUSBIDIO,FVBUSONIO .word 0x3FFFFFFF .section .config_1FC00BF4,code // FPLLIDIV,FPLLMUL .word 0xFFF8FF88 // Internal OSC 8MHz .section .config_1FC00BF8,code // FNOSC,FSOSCEN,IESO,POSCMOD,OSCIOFNC,FPBDIV,FCKSM,WDTPS,FWDTEN,FWDTWINSZ .word 0xFD60CF58 // Internal OSC 8MHz .section .config_1FC00BFC,code // JTAGEN,ICESEL,PWP,BWP,CP .word 0x7FFFFFE7 # # Program main # .global main .global Timer2 .text // Start text area .set noreorder // Don't optimize the order of the instructions as well as don't insert 'nop' instructions after jumps and branches. .ent main main: # ******************* # 1.Initialize # ******************* # (1)Define PortB li t0, 0x0000FF00 // 0x0000FF00 => t0-Register sw t0, TRISB($0) // t0-Register => TRISB+0 li s0, 0x00000001 // 0x00000001 => s0-Register sw s0, PORTB($0) // s0-Register => PORTB+0 # ******************* # 2.Program main # ******************* main1: jal mvLED // CALL mvLED nop jal Timer2 // Wait 1[S] nop j main1 nop .end main #****************************************************************************************** # Function Name : mvLED # Title : Move LED function # Input : # Output : #****************************************************************************************** .ent mvLED mvLED: # ******************* # 1.Initialize # ******************* addiu sp, sp, -4 sw t0, 0(sp) addiu sp, sp, -4 sw t1, 0(sp) addiu sp, sp, -4 sw t2, 0(sp) addiu sp, sp, -4 sw t3, 0(sp) addiu sp, sp, -4 sw t4, 0(sp) addiu sp, sp, -4 sw t5, 0(sp) li t4, 0x00000100 /* 0x000FFFFF => t2-Register */ li t1, 0x00000002 /* 0x00000001 => t1-Register */ li t0, 0x00000001 /* 0x00000000 => t0-Register */ # ******************* # 2.Function main # ******************* move t2, s0 /* t2 <= s0 */ mult t2, t1 /* t2 * t1 */ nop nop mflo t3 /* t3 <= LO */ slt t5, t3, t4 /* t3 t4 => t5 */ bne t5, $0 , mvLED1 /* t5 != 0 */ nop move s0, t0 /* s0 <= t0 */ sw s0, PORTB($0) /* s0-Register => PORTB+0 */ j mvLEDE /* GOTO mvLEDE */ nop mvLED1: move s0, t3 /* s0 <= t4 */ sw s0, PORTB($0) /* s0-Register => PORTB+0 */ # ******************* # 3.Function end # ******************* mvLEDE: lw t5, 0(sp) addiu sp, sp, 4 lw t4, 0(sp) addiu sp, sp, 4 lw t3, 0(sp) addiu sp, sp, 4 lw t2, 0(sp) addiu sp, sp, 4 lw t1, 0(sp) addiu sp, sp, 4 lw t0, 0(sp) addiu sp, sp, 4 jr ra /* Return */ nop .end mvLED #****************************************************************************************** # Function Name : Timer2 # Title : Wait 1[S] # Input : # Output : #****************************************************************************************** .ent Timer2 Timer2: # ******************* # 1.Initialize # ******************* addiu sp, sp, -4 sw t0, 0(sp) addiu sp, sp, -4 sw t1, 0(sp) addiu sp, sp, -4 sw t2, 0(sp) # ******************* # 2.Function main # ******************* # *********************************************** # (1)Define T2CON Register (32Bit) # T2CON(31-16) Unimplemented: Read as e0f # T2CON(15) ON: Timerx On bit # 1 = Starts / 0 = Stop # T2CON(14) Unimplemented: Read as e0f # T2CON(13) SIDL: Stop in Idle Mode bit # 1 = Discontinue module operation when device enters Idle mode # 0 = Continue module operation in Idle mode # T2CON(12-8) Unimplemented: Read as e0f # T2CON(7) TGATE: Timer Gated Time Accumulation Enable bit(3) # When TCS = 1: # This bit is ignored and is read as e0f. # When TCS = 0: # 1 = Gated time accumulation is enabled # 0 = Gated time accumulation is disabled # T2CON(6-4) TCKPS1:TCKPS0: Timerx Input Clock Prescale Select bits # 111 = 1:256 prescale value # 110 = 1:64 prescale value # 101 = 1:32 prescale value # 100 = 1:16 prescale value # 011 = 1:8 prescale value # 010 = 1:4 prescale value # 001 = 1:2 prescale value # 000 = 1:1 prescale value # T2CON(3) T32: 32-Bit Timer Mode Select bit(1) # 1 = Odd numbered and even numbered timers form a 32-bit timer # 0 = Odd numbered and even numbered timers form a separate 16-bit timer # T2CON(2) Unimplemented: Read as e0f # T2CON(1) TCS: Timerx Clock Source Select bit(2) # 1 = External clock from TxCK pin # 0 = Internal peripheral clock # T2CON(0) Unimplemented: Read as e0f # *********************************************** # T2CON:0b00000000000000001000000001100000 <== 1/64,16Bit # T2CON:0b00000000000000001000000001110000 <== 1/256,16Bit li t0, 0b00000000000000001000000001110000 sw t0, T2CON($0) # *********************************************** # (2)Set PR2-Register (PR2[31-16]:Unimplemented, PR2[15-0]timer ) # *********************************************** # PR2 = 0x00007A12: 1Hz (0x7A12;0d31250),FRC 8MHz <== 8MHz/1(pic32)/256(prescale)/1(Hz) li t0, 0x00007A12 sw t0, TMR2($0) # *********************************************** # (3)Timer # *********************************************** lw t0, IFS0($0) andi t1, t0, 0b1111110111111111 // T2IF(9) <= 0 sw t1, IFS0($0) Timer2A: lw t0, IFS0($0) andi t1, t0, 0b0000001000000000 // T2IF beq t1, $0 , Timer2A nop # ******************* # 3.Function end # ******************* lw t2, 0(sp) addiu sp, sp, 4 lw t1, 0(sp) addiu sp, sp, 4 lw t0, 0(sp) addiu sp, sp, 4 jr ra // Return nop .end Timer2