Microcontrollers BME 201
Overview Microcontrollers Notation Registers Timer Concepts Equations
Microcontrollers Made of millions of electrical components A little computer
Programming High-Level Language Assembly Language Machine Language Easy-to-understand abstract language 0 s or 1 s Hard to understand Defined by manufacturer a = b + cAdd a, b, c
Instruction Fetch and Execute 1.Fetch the instruction 2.Figure out what it is 3.Load the operands 4.Do the operation 5.Store the results (if necessary)
Notation Decimal (base 10): 0 – = (1x10 3 )+(2x10 2 )+(3x10 1 )+(4x10 0 )
Notation Binary (base 2): 0 or 1 0b0110 = (0x2 3 )+(1x2 2 )+(1x2 1 )+(0x2 0 ) = = 6 k
Notation Hexadecimal (base 16): 0 – 9, A – F A = 10 B = 11 … 0x5A0F = (5x16 3 )+(10x16 2 )+(0x16 1 )+(15x16 2 ) = a
Notation Page 49 of Handbook 0b x2 B BinaryHex BinaryHex A 1011B 1100C 1101D 1110E 1111F
Data Types Char – Single character: ‘a’, ‘f’, ‘\n’ Int – Whole number: 8, 124, -873 Double/Float – Decimal Number: 4.6, -2.7 Array – Collection of similar data: [1, -4, 3] String – ‘String’ of characters: “Hello World!”
Registers
Timer
Bit-Size 8-bit Counts 0 to (2 8 – 1) 0x00, 0x01, 0x02, … 0xFD, 0xFE, 0xFF 16-bit Counts 0 to (2 16 – 1) 0x0000, 0x0001, 0x0002, … 0xFFFD, 0xFFFE, 0xFFFF
Overflow 0x = 0x01 0x = 0x02 … 0x0F + 1 = 0x10 0x = 0x11 … 0xFE + 1 = 0xFF 0xFF + 1 = ?
Incrementing Counter Counter increments every instruction executed Each instruction executes in 4 clock cycle
Prescale Scales the increment rate 1:2, 1:4, 1:8, 1:32, 1:64, 1:128, 1:256
Start Bytes Start at a specific value 8-bit 0x00 TMR0L 16-bit 0x0000 TMR0H|TMR0 L
Timer Equation 1.Calculate timer increment 1.Determine bit-size 2.Calculate prescale 3.Calculate X (start bytes)
Registers T0CON TMR0H TMR0L Overflow: TMR0IF