EECE 631 Microcomputer System Design Lecture 9 Programming for Microcontrollers PowerPoint PPT Presentation

presentation player overlay
1 / 22
About This Presentation
Transcript and Presenter's Notes

Title: EECE 631 Microcomputer System Design Lecture 9 Programming for Microcontrollers


1
EECE 631Microcomputer System DesignLecture 9
Programming for Microcontrollers
  • Spring 2008
  • Chris Lewis
  • clewis_at_ksu.edu

2
Exam Tuesday
  • I will try to print any manuals that you will
    need
  • You will not need a calculator
  • Binary, Hex
  • Basic Assembly Code
  • Arithmetic
  • Load and Store
  • Branching
  • C Code
  • Rounding
  • Interpolation
  • Pointers
  • Structures
  • C Pre-processor

3
  • NO DIV instruction

4
Using Registers
  • DivStart enter with numbers in r0 r1
  • mov r2,1 bit to control the division
  • Div1 cmp r1,0x80000000 shift r1 left till MSB
    set
  • cmpcc r1,r0 ...or r1gtr0
  • movcc r1,r1,LSL1 shift r1 left if require
  • movcc r2,r2,LSL1 shift r2 left if r1
    shifted
  • bcc Div1 repeat whilst more required
  • mov r3,0 zero r3
  • Div2 cmp r0,r1 test for possible
    subtraction subcs r0,r0,r1 subtract if r0gtr1
  • addcs r3,r3,r2 put relevant bit into
    result movs r2,r2,LSR1 shift control bit
  • movne r1,r1,LSR1 halve unless finished
  • bne Div2 loop if there is more to do
    divide result in r3 Remainder in r0
  • mov r1,r3 result (r0/r1) now in
    r1 mov r15,r14 return from subroutine

5
USART
  • USART10xFFFC0000
  • USART20xFFFC4000

6
(No Transcript)
7
Lines
8
(No Transcript)
9
(No Transcript)
10
Transmit a Character
11
User Concerns
  • Both devices must be configured similarly
  • Baud rate
  • Data length
  • Stop Bits
  • Start Bits
  • Handshaking
  • Hardware handles the details
  • Often, three wires are used
  • RX
  • TX
  • GND
  • DB9 (2, 3, 5)
  • NULL MODEM
  • Transmit and receive lines are swapped

12
Configuration and Control
  • PMC- for clock
  • AIC- for interrupts
  • US_CR Control register
  • Reset-transmit, receive and status
  • Enable/disable- transmit and receive
  • DTR and RTS control
  • Start and Stop Breaks

13
Mode Register US_MR
  • Clock to SCK?
  • Over sampling mode 8x or 16x
  • ACK enable, disable (some protocols)
  • Max iteration (some protocols)
  • Filter ON/OFF (infrared)
  • Manchester ON/OFF
  • Delimiter One Bit or Frame

14
US_IER US_IDR Interrupt Enable/Disable
  • AIC accepts interrupts or not
  • US_IER US_IDR sets causes

One char at at time
15
US_IMR Interrupt mask register
  • Lets software know which event caused interrupt

16
US_CSR Channel Status Register
  • CTS and DSR
  • New character arrived?
  • Transmitter empty?
  • Receiver ready?

17
US_THR US_RHRHolding Registers
  • Data received
  • Data to be sent

18
US_BRGR Baud rate generator register
  • Divides clock by some amount

19
Other registers
  • US_TOR time out register
  • US_TTR time guard register
  • US_FIDI FI over DI ratio ??
  • US_NER Number of errors
  • US_MAN Manchester encoding
  • US_IF filter control

20
Code Structure
  • With or without interrupts
  • Configure PIO controllers to peripheral
  • Enable clock via PMC
  • Configure USART
  • Disable interrupts
  • Reset receiver and transmitter
  • Define the baud rate divisor register
  • Write the Timeguard Register (for slow devices)
  • Clear Transmit and Receive Counters
  • Define the USART mode
  • Enable USART US_CR
  • IF interrupts
  • Select Interrupts to Enable on the US_IER
  • Configure Interrupts on the AIC
  • Enable Interrupts on the AIC
  • NOTE must have ISR in place to handle interrupt

21
Typical Interrupt Service Routine
  • Check to see what caused it
  • Do what only what is necessary
  • Clear condition
  • Return

22
  • __ramfunc void Usart_c_irq_handler(void)
  • AT91PS_USART USART_pt AT91C_BASE_US0
  • unsigned int status
  • status USART_pt-gtUS_CSR // get Usart status
    register
  • if ( status AT91C_US_RXRDY)// Get byte and
    send
  • AT91F_US_PutChar (USART_pt,
    AT91F_US_GetChar(USART_pt))
  • if ( status AT91C_US_OVRE) // clear
    US_RXRDY
  • AT91F_US_GetChar(USART_pt)
  • AT91F_US_PutChar (USART_pt, 'O')
  • if ( status AT91C_US_PARE) // Check parity
    error
  • AT91F_US_PutChar (USART_pt, 'P')
  • if ( status AT91C_US_FRAME) //
    check frame error
  • AT91F_US_PutChar (USART_pt, 'F')
Write a Comment
User Comments (0)
About PowerShow.com