MikroElektronika PIC Microcontrollers PIC16 manuals

Owner’s manuals and user’s guides for PC/workstation barebones MikroElektronika PIC Microcontrollers PIC16.
We providing 4 pdf manuals MikroElektronika PIC Microcontrollers PIC16 for download free by document types: Specifications, User Manual, Datasheet


Table of contents

BASIC CONCEPT

3

Fig. 0-8 High and Low nibbles

9

Fig. 0-17 Register

12

Fig. 0-27 Timers/Counters

21

Fig. 0-28 Timer Operation

22

Fig. 0-31 Watchdog Timer

25

Internal Architecture

26

How to make the right choice

28

● AN3 Third analog input

34

Table 1-1 Pin Assignment

35

Fig. 1-4 CPU Memory

37

Fig. 1-5 ROM Memory Consept

38

Table 1-2 Address Banks

40

Table 1-3 SFR Bank 0

41

Table 1-4 SFR Bank 1

42

Table 1-5 SFR Bank 2

43

Table 1-6 SFR Bank 3

43

Fig.1-7 Interrupt System

44

Chapter 2: Core SFRs

45

Table 2-1

46

Table 2-2

48

Fig. 2-9 Interrupt SFRs

49

Fig. 2-10 INTCON Register

49

Fig. 2-11 PIE1 register

50

Fig. 2-12 PIE2 Register

51

Fig. 2-13 PIR1 Register

52

Fig. 2-14 PIR2 register

53

Fig. 2-15 PCON register

54

Fig. 2-17 PCLATH Registers

55

Chapter 3: I/O Ports

57

Port A and TRISA Register

58

Fig. 3-3 ULPWU Unit

59

Fig. 3-4 Sleep Mode

60

Fig. 3-6 WPUB register

61

Fig. 3-7 Pull-up resistors

61

Fig. 3-8 IOCB register

62

Fig. 3-9 Keyboard Example

62

Fig. 3-10 ICSP Connection

63

Chapter 4: Timers

67

Fig. 4-1 Timer TMR0

68

Fig. 4-2 OPTION_REG Register

68

Fig. 4-5 Timer TMR1

71

Fig. 4-8 TMR1 in timer mode

73

Fig. 4-11 Counter Mode

75

Fig. 4-12 T1CON Register

75

Fig. 4-13 Timer TMR2

77

Fig. 4-14 T2CON Register

77

Chapter 5: CCP Modules

79

Fig. 5-1 CCP1 Module

80

Fig. 5-2 CCP1 in Capture mode

80

Fig. 5-3 CCP1 in Compare mode

81

Fig. 5-4 CCP1 in PWM mode

82

Fig. 5-6 PWM module

83

Fig.5-7 PWM Mode

83

Fig. 5-8 CCP1CON Register

85

Table 5-4 CCP1CON Register

85

Table 5-5 Modes of Operations

86

Fig. 5-9 CCP2 Module

86

Fig. 5-10 CCP2CON Register

87

Table 5-6 CCP2CON Register

87

Fig. 5-12 Half-Bridge Mode

89

Fig. 5-13 Half Bridge Mode

89

Fig. 5-15 Full-Bridge Mode

90

Fig. 5-16 Forward Mode

91

Fig. 5-17 Reverse Mode

91

Fig. 5-18 PWM1CON Register

92

Fig. 5-19 ECCPAS Register

92

EUSART Asynchronous Mode

95

Fig. 6-5 Receiving 9-bit Data

98

Fig. 6-7 Sending Data

99

Fig.6-8 TXSTA Register

99

Fig.6-9 RCSTA Register

100

BAUDCTL Register

104

Fig. 6-11 BAUDCTL Register

105

SPI Mode

107

Fig. 6-13 SPI Mode

108

Fig. 6-14 SPI Mode

108

I²C mode

109

Fig. 6-21 Data Transfer

111

Fig. 6-23 SSPSTAT Register

112

Fig. 6-24 SSPCON Register

114

Fig. 6-25 SSPCON2 Register

115

Fig. 6-27 I²C in Master Mode

116

I²C Master Mode

117

Useful notes

119

Chapter 7: Analog Modules

121

A/D Acquisition Requirements

123

How to Use A/D Converter?

123

Fig. 7-6 Analog Comparator

127

Fig. 7-7 VREF

128

Fig. 7-8 CM1CON0 Regsiter

129

Fig. 7-13 VRCON Register

133

External Clock Modes

137

Fig.8-3 PICflash Program

138

Fig. 8-4 External Oscillator

138

Internal Clock Modes

140

Internal Oscillator Settings

141

Two-Speed Clock Start-up Mode

142

Fail-Safe Clock Monitor

143

Fig.8-18 EECON1 Register

146

Fig. 8-22 Noises

149

Fig. 8-23 Master Clear Pin

149

Chapter 9: Instruction Set

150

Data Transfer Instructions

152

Arithmetic-logic Instructions

152

Bit-oriented Instructions

152

ADDLW - Add literal and W

154

ADDWF - Add W and f

154

ANDLW - AND literal with W

155

ANDWF - AND W with f

156

BCF - Bit Clear f

157

BSF - Bit set f

158

CALL - Calls Subroutine

161

CLRF - Clear f

161

CLRW - Clear W

162

CLRWDT - Clear Watchdog Timer

163

COMF - Complement f

163

DECF - Decrement f

164

GOTO - Unconditional Branch

166

INCF - Increment f

167

IORWF - Inclusive OR W with f

169

MOVF - Move f

170

MOVLW - Move literal to W

171

MOVWF - Move W to f

172

NOP - No Operation

173

Fig. 9-1 f Register

176

Fig. 9-2 f Register

177

SLEEP - Enter Sleep mode

178

SUBWF - Subtract W from f

179

SWAPF - Swap Nibbles in f

180

XORWF - Exclusive OR W with f

181

ELEMENTS OF ASSEMBLY LANGUAGE

185

MACROS AND SUBROUTINES

191

WRITING A NEW PROGRAM

200

Appendix B: Examples

206

ADDITIONAL COMPONENTS

209

EXAMPLE 1

224

EXAMPLE 2

227

EXAMPLE 3

228

Example 4

229

Example 5

231

EXAMPLE 6

233

EXAMPLE 7

235

EXAMPLE 8

237

EXAMPLE 9

239

EXAMPLE 10

240

EXAMPLE 11

242

EXAMPLE 12

244

EXAMPLE 13

246

goto Lsdon

247

EXAMPLE 14

249

EXAMPLE 15

252

EXAMPLE 16

256

COMPILING PROGRAM

261

PROGRAMMING A MICROCONTROLLER

262

Development systems

265

Development system EasyPIC5

266

Table of contents

MikroElektronika

1

Table of Contents

2

To readers note

5

C H A P T E R

6

CODE EDITOR

8

Advanced Editor Features

9

Comment /

10

Uncomment Icon

10

CODE EXPLORER

11

CREATING FIRST PROJECT

12

Compile Icon

15

Debug Icon

15

PROJECTS

18

Managing Source Files

19

Compile and Link Source Code

21

DEBUGGER

22

ERROR WINDOW

24

ASSEMBLY VIEW

25

STATISTICS

26

Chapter

27

Procedures (Details) Window

28

INTEGRATED TOOLS

29

KEYBOARD SHORTCUTS

31

Reference

33

IDENTIFIERS

34

KEYWORDS

35

DATA TYPES

36

For example:

38

Numerals

40

Character Strings

40

CONSTANTS

41

VARIABLES

44

Additional

45

' beginning of a module

46

COMMENTS

48

EXPRESSIONS

49

DECLARATIONS AND STATEMENTS

51

Statements

52

DIRECTIVES

53

' byte at the same time

54

' example for P16F877A

54

PROCEDURES AND FUNCTIONS

55

' some code

56

' routine

56

' case end

58

Main Unit File

61

Compiler

62

Output Generator

62

SCOPE (IDENTIFIER VISIBILITY)

63

PROGRAM ORGANIZATION

65

TYPE CONVERSION

67

Example 1:

68

Example 2:

69

Example 3:

69

' B becomes $00ff

70

' B becomes -10

71

' C becomes 213

71

1 01 11 100

72

0 00 0 00 01

72

1 1 1 10000

72

OPERATORS

78

Runtime Behavior

80

Arithmetic Operators

81

Specific

83

Boolean Operators

84

Logical (Bitwise) Operators

85

' Bb becomes $00a0

86

' Bb becomes $70f4

86

Overview

89

Rules for

89

Comparing

89

Expressions

89

CONDITIONAL STATEMENTS

92

Select Case Statement

93

If Statement

95

Examples

96

For Statement

98

Do..Loop Until Statement

100

While Statement

101

ASM Statement

102

PIC MCU SPECIFIC

103

COMPILER ERROR MESSAGES

106

Built-in and

109

Library Routines

109

BUILT-IN ROUTINES

110

LIBRARY ROUTINES

112

1-Wire Library

113

PIC16F877

115

ADC Library

116

Figure (ADC HW connection)

117

CAN Library

118

CAN_OP_MODE

124

CAN_TX_MSG_FLAGS

124

CAN_RX_MSG_FLAGS

125

CAN_MASK

125

CAN_FILTER

126

CAN_CONFIG_FLAGS

126

PCA82C250

129

Shielded pair, less

129

CANSPI Library

130

CAN Library Constants

136

Compact Flash Library

139

Compact Flash Connector

144

(TOP VIEW)

144

Compact Flash Card

144

EEPROM Library

145

I2C Library

146

LCD Library

150

Commands

151

Figure: LCD HW connection

152

PWM Library

153

Figure: PWM demonstration

154

RS485 Library

155

RS485slave_write

158

Connecting PC and PIC via

160

RS485 communication line

160

SPI Library

161

Value Meaning

163

8. 8. 8. 8. 8. 8. 8. 8

165

USART Library

166

Figure: RS232 HW connection

168

Numeric Formatting Routines

169

Utilities

171

Table of contents

Table of Contents

1

EasyPIC 2

2

To Reader’s Knowledge

3

Chapter 1: The Basics

5

1.1 Why BASIC?

7

1.3 A word about code writing

8

1.6 Running the program

12

1.7 Troubleshooting

13

2.1 Identifiers

17

2.2 Operators

18

2.3 Expressions

18

2.4 Instructions

18

2.5 Data Types

19

2.6 Constants

20

2.7 Variables

20

2.8 Symbols

21

2.9 Directives

22

2.10 Comments

23

2.11 Labels

23

2.12 Procedures and Functions

24

2.13 Modules

26

Chapter 3: Operators

28

3.2 Boolean Operators

30

PORTB = 0xFF

31

Operators)

32

Chapter 4: Control Structures

34

4.2 Loops

39

5.1 Built-in Routines

46

5.2 Library Routines

51

5.2.2 ADC Library

56

5.2.3 CAN Library

58

5.2.3.9 CAN Library Constants

65

5.2.4 CANSPI Library

70

5.2.5 Compact Flash Library

84

Pin diagram of CF memory card

93

5.2.7 Flash Memory Library

96

5.2.8 I2C Library

97

Prototype

100

I2C_Stop

100

5.2.9 LCD Library

101

LCD HW connection

107

5.2.11 Graphic LCD Library

113

5.2.13 PWM Library

126

5.2.13.4 PWM_Stop – Stops PWM

128

PWM demonstration

129

RS485Slave_Write(dat, 1)

134

5.2.15 SPI Library

136

5.2.16 USART Library

139

RS232 HW connection

142

5.2.18 Software I2C

144

5.2.19 Software SPI Library

146

● Clock = 50kHz

147

● Clock idle state low

147

5.2.20 Software UART Library

148

5.2.21 Sound Library

150

5.2.22 Trigonometry Library

151

5.2.23 Utilities

153

Introduction

155

6.1 Interrupt Mechanism

155

6.2 Internal AD Converter

157

6.3 TMR0 Timer

161

6.4 TMR1 Timer

162

6.5 PWM Module

163

7.1 LED Diode

167

7.2 Seven-Segment Displays

169

7.5 Sound Signalization

180

wend

182

8.1 EEPROM Memory

183

8.1.2 Serial EEPROM

184

8.2 Flash Memory

187

8.3 Compact Flash

189

Table of contents

C o n t e n t s

1

PIC book

2

Send us a comment about a

5

CHAPTER 1

6

1.1 Memory unit

8

1.2 Central Processing Unit

8

1.3 Bus

9

1.4 Input-output unit

10

1.5 Serial communication

10

1.6 Timer unit

11

1.7 Watchdog

11

1.9 Program

13

CHAPTER 2

15

CISC, RISC

16

Applications

17

Clock / instruction cycle

17

Pipelining

17

Pin description

18

Types of oscillators

20

XT Oscillator

20

RC Oscillator

20

2.2 Reset

23

2.3 Central Processing Unit

25

Arithmetic Logic Unit (ALU)

25

STATUS Register

27

OPTION register

28

2.4 Ports

31

2.5 Memory organization

33

Program memory

33

Data memory

33

SFR registers

33

Memory Banks

34

Program Counter

35

In System Programming

35

Addressing modes

35

Direct Addressing

35

Indirect Addressing

36

2.6 Interrupts

38

INTCON Register

38

Interrupt initialization

43

2.7 Free-run timer TMR0

45

OPTION Control Register

48

2.8 EEPROM Data memory

50

EECON1 Register

50

Reading from EEPROM Memory

51

Writing to EEPROM Memory

51

CHAPTER 3

53

Arithmetic and logic

54

Bit operations

54

Directing a program flow

54

Instruction Execution Period

55

Word list

55

Chapter 3 - Instruction Set

56

CHAPTER 4

57

Introduction

58

Assembly language

59

Instructions

59

Operands

60

Comments

60

Directives

60

Data Directives

66

CHAPTER 5

72

Chapter 5 - MPLAB

73

Screen prior to installment

79

Installment flow

80

5.2 MPLAB

82

5.4 Designing a project

85

Adjusting project elements

86

Opening a new project

88

Assembler file added

88

5.6 Writing a program

91

5.7 MPSIM Simulator

93

5.8 Toolbar

95

Toolbar icon description

95

CHAPTER 6

98

Macros used in programs

100

Macros WAIT, WAITX

100

Macro PRINT

101

Chapter 6 - Samples

102

Samples

104

Light-Emitting Diodes - LEDs

104

Keyboard

107

Optocoupler

110

Optocoupler on an input line

110

Optocoupler on an output line

112

The Relay

113

Generating a sound

117

Shift registers

121

Input shift register 74HC597

121

Output shift register

124

LCD Display

133

Macro for LCD support

139

Serial Communication

150

Main program:

154

Appendix A

156

A.2 MOVWF Copy W to f

157

A.3 MOVF Copy f to d

157

A.4 CLRW Write 0 in W

158

A.5 Write 0 in f

158

Appendix A - Instruction Set

159

A.8 ADDWF Add W to f

160

A.17 INCF Increment f

164

A.18 DECF Decrement f

165

A.21 COMF Complement f

168

A.23 BSF Set bit b in f

169

A.33 NOP No operation

174

Appendix B

177

B.2 Binary numeric system

178

Appendix B - Numeric Systems

179

Conclusion

181

Appendix C

183

Appendix C - Glossary

184





More products and manuals for PC/workstation barebones MikroElektronika

Models Document Type
PIC Microcontrollers PIC18 User Manual   Advanced PIC18 Projects—CAN Bus Projects, 40 pages
PIC Microcontrollers PIC18 User Manual   mikroElektronika PIC Microcontrollers PIC18 User manual, 88 pages
PIC Microcontrollers PIC12 User's Guide   mikroElektronika PIC Microcontrollers PIC12 User`s guide, 38 pages