Home

Microchip PIC16F876 Development Board User Manual

image

Contents

1. MAX7221_SETSPI MAX7221_CS 0 SPI_SEND16 unsigned int reg lt lt 8 value MAX7221_CS 1 void MAX7221_INTENSITY unsigned char x MAX7221_SETSPI L MAX7221_CS 0 SPI_SEND16 unsigned int INTENSITY lt lt 8 x MAX7221_CS 1 eh void MAX7221_SCAN_LIMIT unsigned char x MAX7221_SETSPI MAX7221_CS 0 Hl SPI_SEND16 unsigned int SCAN_LIMIT lt lt 8 x MAX7221_CS 1 void MAX7221_INIT MAX7221_INTENSITY 0x8 MAX7221_SCAN_LIMIT 0x3 MAX7221_WRITE DECODE_MODE OxF MAX7221_ WRITE SHUTDOWN 0x1 void MAX7221_TESTMODE unsigned char enable Page 30 unsigned char value set up SPI port for MAX7221 select MAX7221 send value de select MAX7221 set up SPI port for MAX7221 select MAX7221 send value de select MAX7221 set up SPI port for MAX7221 select MAX7221 send value de select MAX7221 set intensity set scan limit 4 digits enable display Microchip PIC16F876 Development Board User Manual if enable MAX7221_WRITE DISPLAY_TEST 0x01 enable test mod else MAX7221_WRITE DISPLAY_TEST 0x00 disable test mode void MAX7221_WRITENUM unsigned int value unsigned int dig0 digl dig2 dig3 dig0 value 10000 1000 digl value 1000 100 dig2 value 100 10 dig3 value
2. ifndef MHz define MHz 1000L endif ifndef KHz define KHz 1 endif include lt pic h gt include delay h void SERIAL_CONFIG unsigned char baudrategenval XEN 0 SPEN 0 if defined _16F873 defined _16F874 defined _16F875 defined _16F876 defined _16F877 TRISC 0b10000000 RC7 in TRISC amp 0610111111 RC6 out else error Sorry serial h does not support this PIC endif SPBRG baudrategenval set baud rate generator SPEN 1 serial port enabled TXEN 1 enable serial transmission void SERIAL_SEND unsigned char data TXREG data load TXREG while TRMT wait for flag void SERIAL_SEND16 unsigned int data call SEND twice SERIAL_SEND unsigned char data amp OXFFOO gt gt 8 SERIAL_SEND unsigned char data amp Ox00FF endif delay h Delay functions for the PIC delay h Delay functions for the PIC k k Functions available KK DELAY_US x Page 32 Microchip PIC16F876 Development Board User Manual Hz Delay specified number of microseconds Ke DELAY_MS x Ex Delay specified number of milliseconds kk Note that there are range limits x must not exceed 255 for xtal frequencies gt 12MHz the range for DELAY_US is even smaller x DELAY_US is implemented as an inline style macro function kk
3. MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 SPI_SEND CMD_READ send read command SPI_SEND startaddr send register starting address for i 0 i lt len i dest i SPI RECIEVE get the data port mask de select MCP2510 void MCP2510_RTS unsigned char port unsigned char mask unsigned char rtsnum MCP2510_SETSPI setup SPI port for MCP2510 Page 24 Microchip PIC16F876 Development Board port amp mask SPI_SEND rtsnum Port mask void MCP2510_BITMODIFY unsigned unsigned MCP2510_SETSPI port amp mask SPI_SEND CMD_BITMODIFY SPI_SEND addr SPI_SEND bitmask END SPT Si data port mask void MCP2510_R ES MCP2510 SETSPI port amp mask SPI SEND CMD RES port mask DELAY_US 25 ET void MCP2510_TRANSMIT_STD unsigned char port unsigned char id unsigned char status unsigned char packet 13 ET unsigned char port User Manual select MCP2510 must be RTSO RTS1 or RTS2 de select MCP2510 char port char addr unsigned char mask unsigned char bitmask unsigned char data setup SPI port for MCP2510 select MCP2510 bit modify command send register address send bitmask send data de select M
4. 5 Specify the proper port settings o Baud rate as specified in software on the PIC 8 data bits No parity 1 stop bit Hardware flow control 6 That s it The program should now be ready to communicate with the PIC OOG Page 15 Microchip PIC16F876 Development Board User Manual D PIC Programming In order for the board to do anything the PIC s Flash instruction memory obviously must be programmed with code for the PIC to execute The PIC16F876 Development Board does not include an on board programmer to do this a separate programmer module must be used A number of inexpensive programmers can be purchased or easily constructed One readily available programmer is the P16PRO40 one of these is available for use in the Senior Design lab in Town Hall The P16PRO40 includes a ZIF socket for the PIC and it interfaces with the PC via the parallel port This programmer takes the compiled hex code from the PC and programs it into the PIC An additional PC software package is necessary to interface with the PIC programmer One such program is WinPicProg available free of charge at http www winpicprog co uk The necessary settings for this program to function properly with the P16PRO40 are shown in the screenshot in Figure 3 1 er Hardware Settings Programmer Type Custom Settings Programmer Vdd Vpp Clock Input C DO C DO C DO C ERROR DI D1 D1 SES D2 D2 D2 C PE C D3 D3 D3 ACK C D4 D4 D4 C BSY C D D5 C
5. G 5 oO he ei EES d MT E es a gt SC Fa BZ los ke les rare rie id Figure 2 9 PIC Development Board layout Page 10 Microchip PIC16F876 Development Board User Manual 3 Board Operation A Getting Started The PIC16F876 Development Board plugs into a standard wall socket with the included AC adapter The board does not include an on off switch so the PIC begins executing the code in its instruction memory immediately after it receives power Obviously if no code has yet been programmed into the PIC the board will not do anything after being plugged in Instructions for programming the PIC are given in Section 3 D PIC Programming An initialization routine has been written to perform the necessary setup procedures and execute simple tests to verify that the board is working properly This routine or at least the vital parts of it should be programmed into the PIC and performed every time the board is started to ensure proper operation It currently performs the following operations e selects the HS high speed crystal oscillator type e enables the power up timer e disables the watchdog timer e disables low voltage programming e sets up the I O pins e configures the ADC analog to digital converter turns the speaker on and emits a start up beep initializes and writes a test string to the LCD initializes and tests the 7 segment LEDs with a simple count down rea
6. 0x44 0x45 0x46 0x47 0x48 0x49 Ox4A h hel Fy Lf KH User Manual Acceptance Filter 2 Acceptance Filter 2 Ext Identifier High Ext Identifier Low RXnBF Pin Control and Status Register TXnRTS Pin Control and Status Register CAN Status Register CAN Control Register EI Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Acceptance Filter Identifier High Acceptance Filter Identifier Low Transmitter error counter Identifier High Identifier Low Identifier High Identifier Low Identifier High Identifier Low Identifier High Identifier Low Identifier High Identifier Low x ct CT ct x x tootoo ta CT ct x Ann EG HE BW GA D Ww bi pm oo pn oo ANN x a Reciever error counter Acceptance Mask 0 Std Identifier High Acceptance Mask 0 Std Identifier Low Acceptance Mask 0 Ext Identifier High Acceptance Mask 0 Ext Identifier Low Acceptance Mask 1 Std Identifier High Acceptance Mask 1 Std Identifier Low Acceptance Mask 1 Ext Identifier High Acceptance Mask 1 Ext Identifier Low Configuration Register 3 Configuration Register 2 Configuration Register 1 Interrupt Enable Register Interrupt Flag Register Error flag register Trans
7. MSB gt LSB SPI_RECIEVE16 ER Returns 16 bit uint data recieved over SPI k k Updates TE 04 29 2002 Nick Veys BE Inital Revision Zi ifndef __SPI_H define __SPI_H include lt pic h gt void SPI_CONFIG unsigned char stat unsigned char con SSPEN 0 disable SPI port for reconfiguration SSPSTAT stat set SSPSTAT SSPCON con set SSPCON SSPEN 1 re enable SPI port void SPI_SEND unsigned char data SSPBUF data write out to buffer while SSPIF wait for flag SSPIF 0 clear flag unsigned char SPI_RECEIVE Page 34 Microchip PIC16F876 Development Board User Manual SSPBUF 0 load 0 while SSPIF wait for data received SSPIF 0 handle flag return SSPBUF return the value void SPI_SEND16 unsigned int data call SEND twice SPI_SEND unsigned char data amp OXFFOO gt gt 8 SPI_SEND unsigned char data amp OxOOFF unsigned int SPI_RECEIVE16 call RECEIVE twice return unsigned int SPI_RECEIVE lt lt 8 SPI_RECEIVE endif Page 35 Microchip PIC16F876 Development Board User Manual C Initialization amp Diagnostics Routine An initialization routine has been written to perform the necessary setup procedures and execute simple tests to verify that the board is working proper
8. This library requires PIC_XTAL to be define d before inclusion ES the MHz and KHz suffixes may be used for a x1000 or x1 Updates SC 04 29 2002 Nick Veys EE Inital Revision SE Set up rough timing xx ifndef __DELAY_H define __DELAY_H ifndef MHz define MHz 1000L endif ifndef KHz define KHz 1 endif ifndef PIC_XTAL error PIC_XTAL not defined endif if PIC_XTAL gt 12MHz define DELAY US x unsigned char _dent dent x PIC_XTAL 12MHz while _dent 0 continue else define DELAY US x unsigned char _dent _dent x 12MHz PIC_XTAL 1 while _dent 0 continue endif void DELAY_MS unsigned char cnt if PIC_XTAL lt 2MHz do DELAY_US 996 while cnt endif if PIC_XTAL gt 2MHz unsigned char i do Page 33 Microchip PIC16F876 Development Board User Manual DELAY_US 250 while i while cnt endif endif spi h Functions for using the SPI port on the PIC spi h Functions for using the SPI port on PICs that have them k k Functions available Ro SPI CONFIG stat con KR Sets SSPSTAT and SSPCON registers ER SPI_SEND data Er Sends 8 bit data out over SPI SPI_RECIEVE KR Returns 8 bit data recieved over SPI SPI_SEND16 data ZS Sends 16 bit uint data over SPI
9. Write test string Temperature update loop Line 2 temp Break up temperature digits Page 37 LCD_PU LCD_OU LCD_OU Microchip PIC16F876 Development Board S Temperature 13 LCD_PUTS temp 3 DATA OxDF _DATA F DELAY_MS 100 if timer 1 if count 0 count 5 MAX7221_WRITENUM timer timer else count User Manual Temperature header string put actual temp value out degree symbol Fahrenheit wait 100ms til next update Page 38 Microchip PIC16F876 Development Board User Manual 5 Additional Resources Dec02 12 Project Web Site http www kilohm net seniord http seniord ee iastate edu dec0212 CIA CAN in Automation CAN protocol overview http www can cia de can protocol Fairchild Semiconductor http www fairchildsemi com HI TECH Software http www htsoft com Maxim Integrated Products http www maxim ic com National Semiconductor http www national com ON Semiconductor http www onsemi com P16PRO amp PICALL PIC Programmer http www picallw com Philips Electronics http www philips com Planet Microchip http www microchip com Veys com PIC tutorials http www veys com WinPicProg Development Site http www winpicprog co uk Page 39
10. mask TXB2SIDH packet 13 RTS2 nothing free try again de select MCP2510 unsigned char mask unsigned char eid unsigned char data storage for MCP2510 s status byte storage for complete packet packet 0 id 0 amp 0x07 lt lt 5 id 1 amp OxF8 gt gt 3 packet 1 id 1 amp 0x07 lt lt 5 eid 0 amp 0x03 0x08 packet 2 eid 1 packet 3 eid 2 packet 4 dlc amp Ox0F packet 5 data 0 packet 6 datall packet 7 datal2 packet 8 data 3 packet 9 data 4 packet 10 data 5 packet 11 data 6 packet 12 data 7 status MCP2510_STATUS port mask get status register MCP2510_SETSPI port amp mask EXTLOOP void MCP2510_TRANSMIT_R if status amp 0x02 MCP2510_RTS port mask else if status amp 0x10 MCP2510_RTS port mask else if status amp 0x40 MCP2510_WRITE_SEQUENCE port MCP2510_WRITE_SEQUENCE port setup SPI port for MCP2510 select MCP2510 TXO is free mask TXBOSIDH packet 13 RTSO TX1 is free 139 mask TXB1SIDH packet RTS1 TX2 is free MCP2510_WRITE_SEQUENCE port mask TXB2SIDH packet 13 MCP2510_RTS port mask RTS2 else goto EXTLOOP nothing free try again port mask de select MCP2510 unsigned char status
11. 10 Wait for it to start up ADGO 1 Start the conversion while ADGO Wait for it to complete ADON 0 The the ADC off ADIF 0 Clear interrupt flag Page 36 Microchip PIC16F876 Development Board User Manual x ADRESH lt lt 8 ADRESL x long x 500 1024 return x void separateDigits unsigned int num retval 2 num 10 num retval 2 retval l num 100 num retval 1 retval 1 10 retval 0 num 1000 num retval 0 retval 0 100 retval 0 0 retval 1 0 retval 2 0 if retval 0 0 if retval 1 0 retval 0 retval 1 else retval 0 void main unsigned char temp 3 unsigned int timer int count TRISB TRISC 0b00000001 0610010000 ADCON1 0x84 SPEAKER 0 DELAY MS 25 SPEAKER 1 LCD_INITIALIZE 2 MAX7221_INIT MAX7221_WRITEVAL 0x0050 LCD PUTS Hello World 13 timer 50 count 5 while 1 LCD_SET_DDRAM 40 separateDigits READ_TEMPERATURE unsigned char retval Get ones digit Get tens digit Get hundreds digit Make them ASCII check for leading 0 s set up i o pins configure ADC Speaker on Beep for 25ms Speaker off Initialize the 2 line LCD Initialize the seven segment display
12. Wait gt 15ms for Vcc to rise LCD_OUT_UPPER_NYBBLE 0x30 Function Set 8 bit LCD_OUT_UPPER_NYBBLE 0x30 Function Set 8 bit LCD_OUT_UPPER_NYBBLE 0x30 Function Set 8 bit LCD_OUT_UPPER_NYBBLE 0x20 Function Set 4 bit if lines 1 LCD_OUT_COMMAND 0x20 4 bit interface 1 line 5x7 font else if lines 2 LCD_OUT_COMMAND 0x28 4 bit interface 2 lines 5x7 font LCD_OUT_COMMAND 0x0C Display on no cursor no blink LCD_CLEAR Display clear LCD_OUT_COMMAND 0x06 Auto increment cursor void LCD_PUTS const char s unsigned char len unsigned char i for i 0 LCD_OUT_DATA s endif i lt len i i Page 29 Put out each character Microchip PIC16F876 Development Board User Manual max7221 h Functions for controlling the 7 segment display driver Seven segment display void MAX7221_WRITE unsigned char reg ifndef __MAX7221_H define __MAX7221_H include lt pic h gt include spi h define MAX7221_CS RCO Chip Select define DIGO_ADDR 0x01 define DIG1_ADDR 0x02 define DIG2_ADDR 0x03 define DIG3_ADDR 0x04 define DIG4_ADDR 0x05 define DIG5_ADDR 0x06 define DIG6_ADDR 0x07 define DIG7_ADDR 0x08 define DECODE_MODE 0x09 define INTENSITY Ox0A define SCAN_LIMIT 0x0B define SHUTDOW OXOC define DISPLAY TEST OXOF define MAX7221_SETSPI SPI_CONFIG 0x40 0x01
13. unsigned char packet 5 packet 0 id 0 EM unsigned char port unsigned char id amp 0x07 unsigned char mask unsigned char eid storage for complete packet lt lt 5 id 1 amp OxF8 gt gt 3 Page 26 Microchip PIC16F876 Development Board User Manual packet 1 id 1 amp 0x07 lt lt 5 eid 0 amp 0x03 0x08 packet 2 eid 1 packet 3 eid 2 packet 4 0x40 status MCP2510_STATUS port mask get status register MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 REMLOOP if status amp 0x02 TXO is free MCP2510_WRITE_SEQUENCE port mask TXBOSIDH packet 5 MCP2510_RTS port mask RTSO else if status amp 0x10 TX1 is free MCP2510_WRITE_SEQUENCE port mask TXB1SIDH packet 5 MCP2510_RTS port mask RTS1 else if status amp 0x40 TX2 is free MCP2510_WRITE_SEQUENCE port mask TXB2SIDH packet 5 MCP2510_RTS port mask RTS2 else goto REMLOOP nothing free try again port mask de select MCP2510 endif Page 27 Microchip PIC16F876 Development Board User Manual Icd h Functions for controlling and sending output to the LCD ifndef __LCD_H define __LCD_H include lt pic h gt include delay h define LCD_E RB1 LCD define LCD_RW RB2 LCD define LC
14. 10 MAX7221_WRITE DIGO_ADDR unsigned int dig0 MAX7221_WRITE DIG1_ADDR unsigned int digl MAX7221_WRITE DIG2_ADDR unsigned int dig2 MAX7221_WRITE DIG3_ADDR unsigned int dig3 void MAX7221_WRITEVAL unsigned int value MAX7221_WRITE DIGO_ADDR value amp 0xF000 gt gt 12 MAX7221_WRITE DIG1_ADDR value amp 0x0F00 gt gt 8 MAX7221_WRITE DIG2_ADDR value amp 0x00FO gt gt 4 MAX7221_WRITE DIG3_ADDR value amp 0x000F endif serial h Functions for using the RS 232 serial port a serial h Functions available SE kk kk ERIAL S Send RIAL_RECIE ERIAL_SEND16 data Send 16bit data ERIAL RECIEVE16 END data 8bit data VE SE kk kk kk kk Updates RR 04 29 2002 Nick Veys ER Inital Revision ER 05 06 2002 Nick Veys Added most stuff need broader MCU support 8N1 RIAL CONFIG baudrategenval Sets up baud rate This library requires PIC_XTAL to b the MHz and KHz suffixes may be used for a x1000 or xl Functions for using the UART on PICs that have them Defaults to ASYNC low speed define d before inclusion better TX delay Page 31 Microchip PIC16F876 Development Board User Manual Er Reception not implemented need good methodology first u ifndef __SERIAL_H define SERIAL H
15. CP2510 unsigned char mask setup SPI port for MCP2510 select MCP2510 reset MCP2510 command de select MCP2510 let it reset unsigned char mask unsigned char dlc unsigned char data storage for complete packet packet 0 id 0 amp 0x07 lt lt 5 id 1 amp OxF8 gt gt 3 packet 1 id 1 amp 0x07 lt lt 5 packet 2 0 packet 3 0 packet 4 dlc amp Ox0F packet 5 data 0 packet 6 data 1 packet 7 data 2 packet 8 data 3 packet 9 data 4 packet 10 data 5 packet 11 data 6 packet 12 data 7 status MCP2510_STATUS port mask get status register MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 STDLOOP if status amp 0x02 TXO is free MCP2510_WRITE_SEQUENCE port mask TXBOSIDH packet 13 MCP2510_RTS port mask RTSO else if status amp 0x10 TX1 is free MCP2510_WRITE_SEQUENCE port mask TXB1SIDH packet 13 MCP2510_RTS port mask RTS1 else if status amp 0x40 TX2 is free Page 25 void MCP2510_TRANSMIT_EXT unsigned char port unsigned char id unsigned char dlc Microchip PIC16F876 Development Board MCP2510_WRITE_SEQUENCE port MCP2510_RTS port mask else goto STDLOOP port mask unsigned char status unsigned char packet 13 User Manual
16. D_RS RB3 LCD define LCD DB4 RB4 define LCD_DB5 RB5 define LCD DB6 RB6 define LCD_DB7 RB7 LCD_RS 0 LCD_RW 0 LCD_DB7 cmd amp 0x80 1 0 LCD_DB6 cmd amp 0x40 1 0 LCD_DB5 cmd amp 0x20 1 0 LCD_DB4 cmd amp 0x10 1 0 LCD_E 1 DELAY_US 1 LCD_E 0 LCD_DB7 cmd amp 0x08 1 0 LCD_DB6 cmd amp 0x04 1 0 LCD_DB5 cmd amp 0x02 1 0 LCD_DB4 cmd amp 0x01 1 0 LEDE 1 DELAY_US 1 LCD_E 0 DELAY_MS 15 void LCD_OUT_COMMAND unsigned char cmd Enable control line Read Write control line Register Select control line void LCD_OUT_UPPER_NYBBLE unsigned char nybble LCD_RS 0 LCD_RW 0 LCD_DB7 nybble amp 0x80 LCD_DB6 nybble amp 0x40 LCD_DB5 nybble amp 0x20 LCD_DB4 nybble amp 0x10 LCD_E 1 DELAY US 1 LCD_E 0 DELAY_MS 15 void LCD_OUT_DATA unsigned char LCD_RS 1 LCD_RW 0 LCD_DB7 errr data amp 0x80 1 0 OOOO Sen Sen data EL Page 28 Output a command byte Command mode Write mode Bit 7 Bit 6 Bit 5 Bit 4 DB7 DB6 DB5 DB4 Strobe Wait a Strobe E high wee bit E low DB7 DB6 DB5 DB4 Bit Bit 2 Bit 1 Bit 0 Strobe E high W
17. Data Byte 5 TXB1D6 0x4C Transmit Buffer 1 Data Byte 6 TXB1D7 0x4D Transmit Buffer 1 Data Byte 7 TXB2CTRL 0x50 Transmit Buffer 2 Control Register TXB2SIDH 0x51 Transmit Buffer 2 Std Identifier High TXB2SIDL 0x52 Transmit Buffer 2 Std Identifier Low XB2EID8 0x53 Transmit Buffer 2 Ext Identifier High XB2EIDO 0x54 Transmit Buffer 2 Ext Identifier Low TXB2DLC 0x55 Transmit Buffer 2 Data Length Code TXB2D0 0x56 Transmit Buffer 2 Data Byte 0 TXB2D1 0x57 Transmit Buffer 2 Data Byte 1 TXB2D2 0x58 Transmit Buffer 2 Data Byte 2 TXB2D3 0x59 Transmit Buffer 2 Data Byte 3 TXB2D4 0x5A Transmit Buffer 2 Data Byte 4 TXB2D5 0x5B Transmit Buffer 2 Data Byte 5 TXB2D6 0x5C Transmit Buffer 2 Data Byte 6 TXB2D7 0x5D Transmit Buffer 2 Data Byte 7 RXBOCTRL 0x60 Recieve Buffer 0 Control Register RXBOSIDH 0x61 Recieve Buffer 0 Std Identifier High RXBOSIDL 0x62 Recieve Buffer 0 Std Identifier Low RXBOEID8 0x63 Recieve Buffer 0 Ext Identifier High RXBOEIDO 0x64 Recieve Buffer 0 Ext Identifier Low RXBODLC 0x65 Recieve Buffer 0 Data Length Code RXBODO 0x66 Recieve Buffer 0 Data Byte 0 RXBOD1 0x67 Recieve Buffer 0 Data Byte 1 RXBOD2 0x68 Recieve Buffer 0 Data Byte 2 RXBOD3 0x69 Recieve Buffer 0 Data Byte 3 RXBOD4 Ox6A Recieve Buffer 0 Data Byte 4 RXBODS 0x6B Recieve Buffer 0 Data Byte 5 RXBOD6 0x6C Recieve Buffer 0 Data Byte 6 RXBOD7 0x6D Recieve Buffer 0 Data Byte 7 RXBIC
18. Microchip PIC16F876 Development Board User Manual e em i i i au u id Hello worta ooo g E D 3 O 0 HOE ie 2 Microchip PIC16F876 Development Board User Manual Table of Contents Ds OV ET VICW ss Dee ee ese Ge sig N Ge og be ge ve Ge 3 2 Board Design is ee unbe 4 A Functional Desidn osse sessies es Ke Ng be so doe Ee es eds gees 4 B Schematics amp Design Parts List csccscccsscscsesscceeeee 5 C Layout E 10 3 Board Operation cccseccsscssssscscesesccvcesesscsccsessevceses 11 A Getting Started WE 11 B Component Description sesse Re Ge Ge Ge 12 C Getting Input 15 D PIC Programming edd NEEN eene ENEE svete 16 4 Application Development see NENNEN ENEE En 17 A Development Languages amp Tools ssr0sssssenssnsnenonnee 17 B Software Libraries ss dese EG Ge ENEE dee 18 C Initialization amp Diagnostics Routine cccccsssceee 36 5 Additional Resources cececccceccccsccccsceccscecees 39 Page 2 Microchip PIC16F876 Development Board User Manual 1 Overview The PIC16F876 Development Board was designed as part of a Senior Design project in Electrical and Computer Engineering at Iowa State University The purpose of this project was to develop a low cost development board that future Senior Design teams could use to develop a PIC microcontroller based solution for their own projects This b
19. S const char s unsigned char len Outputs a string to the LCD max7221 h Functions for controlling the 7 segment display driver MAX7221 SETSPI Sets up SPI port for use w the MAX7221 MAX7221_WRITE unsigned char reg unsigned char value Used by other functions to send output and commands to the MAX7221 MAX7221_INTENSITY unsigned char x Send intensity value to the MAX7221 used by MAX7221_INIT MAX7221_SCAN_LIMIT unsigned char x Send scan limit value to the MAX7221 used by MAX7221_INIT MAX7221_INITO Initializes the MAX7221 MAX7221_TESTMODE unsigned char enable Enable disable test mode MAX7221_WRITEVAL unsigned int value Write a value to the display value in decimal MAX7221_WRITENUM unsigned int value Write a value to the display value in hexadecimal serial h Functions for using the RS 232 serial port SERIAL_CONFIG baudrategenval Sets up baud rate SERIAL_SEND data Send 8 bit data SERIAL_RECEIVE Receive 8 bit data SERIAL_SEND16 data Send 16 bit data SERIAL_RECEIVEI6 Receive 16 bit data Page 19 Microchip PIC16F876 Development Board User Manual delay h Delay functions for the PIC e DELAY_US x Delay specified number of microseconds e DELAY_MS x Delay specified number of milliseconds en h Functions for using the SPI port on the PIC SPI_CONFIG stat con Sets SSPSTAT and SSPCON registers e SPI_SEND data Sends 8 bit data out over SPI e SPI_RECEIVE Returns 8 bit data received
20. STB C DB D6 C AutoLF Ei D7 C Init C STB STB C Selin C AutoLF C AutoLF Iw Invert C Init C Ini i C Init C Selin C Selin i C Selin M Invert M Invert M Invert Iw Invert v Invert On On j Low Low Figure 3 1 WinPicProg settings RAAR RM Page 16 Microchip PIC16F876 Development Board User Manual 4 Application Development A Development Languages amp Tools It is possible to develop software applications using either the PIC s native Assembly language or C The necessary IDE Integrated Development Environment packages for either language are readily available The best language to use depends on the specific application Here are some of the advantages and disadvantages to using either language Assembly Good for writing efficient and compact code e g for real time applications Small instruction set is easy to learn Longer development time Must learn the PIC instruction set Code is less readable No need to learn another programming language Quick development time Code is easy to read and document Code may be less efficient not as much low level control 0 The IDE used for developing Assembly code is MPLAB Microchip s proprietary IDE supporting all of the company s PIC devices It can be downloaded for free from the Microchip website The toolset has most of the standard features for writing and debugging code found in other IDEs including a color coded source code text edi
21. TRL 0x70 Recieve Buffer 1 Control Register RXB1SIDH 0x71 Recieve Buffer 1 Std Identifier High RXB1SIDL 0x72 Recieve Buffer 1 Std Identifier Low RXB1EID8 0x73 Recieve Buffer 1 Ext Identifier High RXB1EIDO 0x74 Recieve Buffer 1 Ext Identifier Low RXB1DLC 0x75 Recieve Buffer 1 Data Length Code RXB1D0 0x76 Recieve Buffer 1 Data Byte 0 RXB1D1 0x77 Recieve Buffer 1 Data Byte 1 RXB1D2 0x78 Recieve Buffer 1 Data Byte 2 RXB1D3 0x79 Recieve Buffer 1 Data Byte 3 RXB1D4 0x7A Recieve Buffer 1 Data Byte 4 RXB1D5 0x7B Recieve Buffer 1 Data Byte 5 RXB1D6 0x7C Recieve Buffer 1 Data Byte 6 RXB1D7 0x7D Recieve Buffer 1 Data Byte 7 CMD_READ 0x03 Read Command CMD_WRITE 0x02 Write Command CMD_BITMODIFY 0x05 Bit modify Command CMD_READSTATUS OxAO Read Status Command poll CMD_RESET 0xCO Reset Command RTSO 0x81 Request to send Commands RTS1 0x82 RTS2 0x84 MCP2510_SETSPI SPI_CONFIG 0x00 0x10 unsigned char MCP2510_STATUS unsigned char port unsigned char mask Page 23 Microchip PIC16F876 Development Board User Manual unsigned char temp MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 SPI_SEND CMD_READSTATUS read status command temp SPI_RECIEVE get it temp SPI_RECIEVE it s sent twice port mask de select MCP2510 return temp return it void MCP2510_WRITE unsigned
22. ait a wee bit Strobe E low Wait for instruction to complete Output upper nybble command Bit 7 Bit 6 BLES Bit 4 DB7 DB6 DB5 DB4 Strobe E high Wait a wee bit Strobe E low Wait for instruction to complete Output a data byte Data mode Write mode Bit 7 gt DB7 Microchip PIC16F876 Development Board User Manual LCD_DB6 data amp 0x40 1 0 Bit 6 gt DB6 LCD_DB5 data amp 0x20 1 0 Bit 5 gt DB5 LCD_DB4 data amp 0x10 1 0 Bit 4 gt DB4 LEDE de Strobe E high DELAY_US 1 Wait a wee bit LCD_E 0 Strobe E low LCD_DB7 data amp 0x08 1 0 Bit 3 gt DB7 LCD_DB6 data amp 0x04 1 0 Bit 2 gt DB6 LCD_DB5 data amp 0x02 1 0 Bit 1 gt DB5 LCD_DB4 data amp 0x01 1 0 Bit 0 gt DB4 LED Fe Sl Strobe E high DELAY_US 1 Wait a wee bit LCD_E 0 Strobe E low DELAY_MS 15 Wait for instruction to complete define LCD _CLEAR LCD OUT COMMAND 0x01 Clear command define LCD_HOME LCD_OUT_COMMAND 0x02 define LCD_SET_CGRAM x LCD_OUT_COMMAND 0x40 x amp Ox3F define LCD_SET_DDRAM x LCD_OUT_COMMAND 0x80 x amp 0x7F void LCD_INITIALIZE unsigned char lines Initialize the display LCD_E 0 Initialize all control signals LCD_RW 0 LCD_RS 0 DELAY_MS 20
23. changes during the project development stages The PIC orchestrates the operation of the rest of the components on the board which provide input and output for the microcontroller Code for the PIC can be written using either the native assembly language or another language such as C More information on the software libraries that have already been written for the board as well as guidelines for writing your own software can be found in Section 4 Application Development The development board does not include an on board programmer for the PIC The PIC can be programmed with a separate programmer module Fairly inexpensive programmers can be purchased from a number of sources The programmer that was used for the development of this board was the P16PRO40 This programmer is available for use by any Senior Design team in the Senior Design labs Instructions on how to use this programmer are given in Section 3 D PIC Programming If much of the PIC s functionality seems foreign to you don t despair For more in depth information on using the PIC and its many capabilities the best place to go is the Microchip website at http www microchip com In addition to a datasheet for the 16F876 the site has a number of tutorials and other documentation to help learn how to configure the PIC and use its numerous Page 12 Microchip PIC16F876 Development Board User Manual functions There are also several other user friendly resources on the In
24. char port unsigned char mask unsigned char addr unsigned char data MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 SPI_SEND CMD_WRITE send write command SPI_SEND addr send register address SPI_SEND data send the data port mask de select MCP2510 void MCP2510_WRITE_SEQUENCE unsigned char port unsigned char mask unsigned char startaddr unsigned char data unsigned char len unsigned char i MCP2510_SETSPI setup SPI port for MCP2510 port amp mask select MCP2510 SPI_SEND CMD_WRITE send write command SPI_SEND startaddr send register starting address for i 0 i lt len i SPI_SEND datali send the data port mask de select MCP2510 unsigned char MCP2510_READ unsigned char port unsigned char mask unsigned char addr unsigned char temp MCP2510_SETSPL setup SPI port for MCP2510 port amp mask select MCP2510 SPI_SEND CMD_READ send read command SPI_SEND addr send register address temp SPI_RECIEVE get the data port mask de select MCP2510 return temp return the data void MCP2510_READ_SEQUENCE unsigned char port unsigned char mask unsigned char startaddr unsigned char dest unsigned char len unsigned char i
25. d ER the MCP2510 chip select line i e if the MCP2510 is on PORTA s ak bit 4 port amp PORTA mask 0600010000 0x10 Recommend this KH be defined in the main program code rather than stated every use k k Updates KK 04 29 2002 Nick Veys Ex Inital Revision SE 05 30 2002 Nick Veys xk Added SPI_SETUP s to a few functions HE Small documentation tweaks Ma 10 25 2002 Nick Veys FR Added transmission routines NEED OPTIMIZATION aK 10 26 2002 Nick Veys XX Optimized transmission routines RR Added WRITE SEOUENCE function xf ifndef __MCP2510_H define __MCP2510_H include spi h include delay h define RXFOSIDH 0x00 Acceptance Filter 0 Std Identifier define RXFOSIDL 0x01 Acceptance Filter 0 Std Identifier define RXFOEID8 0x02 Acceptance Filter 0 Ext Identifier define RXFOEIDO 0x03 Acceptance Filter 0 Ext Identifier define RXF1SIDH 0x04 Acceptance Filter 1 Std Identifier define RXF1SIDL 0x05 Acceptance Filter 1 Std Identifier define RXF1EID8 0x06 Acceptance Filter 1 Ext Identifier define RXF1EIDO 0x07 Acceptance Filter 1 Ext Identifier define RXF2SIDH 0x08 Acceptance Filter 2 Std Identifier define RXF2SIDL 0x09 Acceptance Filter 2 Std Identifier Page 21 define define define define define define define define define define defin
26. ds the temperature and displays it on the LCD The source code for this routine can be found in Section 4 C Initialization amp Diagnostics Routine It can be modified as necessary to perform any other initializations that might be necessary for your particular application or to perform additional functionality tests For example it might be beneficial to include functions to test for proper operation of the CAN and RS 232 interfaces Page 11 Microchip PIC16F876 Development Board User Manual B Component Description PIC16F876 The Microchip PIC16F876 is a 28 pin microcontroller with a number of features that would be helpful in providing a microcontroller based solution for a wide variety of Senior Design projects Some of these features include e easy to learn instruction set only 35 single word instructions e 20 MHz operating frequency e 8192 14 bit words of Flash program memory e 368 bytes of data memory e 256 bytes of additional EEPROM data memory e 13 programmable interrupts e SPI DC and USART serial I O e 22 I O ports e 5 10 bit analog to digital channels e 3 timers e 2capture compare modules e PWM pulse width modulation e 8 level hardware stack The 16F876 is well suited to a wide variety of advanced automotive industrial appliance and consumer applications Its program memory space is implemented with electrically re programmable Flash memory which is very desirable for making quick code
27. e define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define RXF2EID8 RXF2EIDO BFPCTRL TXRTSCTRL CANSTA CANCTRL RXF3SIDH RXF3SIDI RXF3EID8 RXF3EIDO RXF4SIDH RXF4SIDI RXF4EID8 RXF4EIDO RXF5SIDH Ly Ly RXF5SIDI Ly RXFSEID8 RXF5EIDO TEC REC RXMOSIDH RXMOSIDI RXMOEID8 EIDO SIDH RX RX RX RX SIDI ER Ly EID8 RXMI1EIDO CNF3 CNF2 CNF1 CANIN CANINTF EFLG E TXBOCTRI TXBOSIDH Ly TXBOSIDI TXBODLC TXBODO TXBOD1 TXBOD2 TXBOD3 TXBOD4 TXBOD5 TXBOD6 TXBOD7 TXB1CTRI TXB1SIDH Ly XBOEID8 XBOEIDO Ly TXB1SIDI TXB1DLC TXB1DO TXB1D1 TXB1D2 TXB1D3 TXB1D4 Ly XB1EID8 XB1EIDO Microchip PIC16F876 Development Board Ox0A 0x0B OXOC 0x0D OXOE Ox0F 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 0x1 D Op mv o JO UG GA H CH 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 Ox2A 0x2B 0x2C 0x2D 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 Ox3A 0x3B 0x3C 0x3D 0x40 0x41 0x42 0x43
28. er to the final report on the Senior Design project website Page 5 Microchip PIC16F876 Development Board User Manual RBI RB2 RB3 PGM RB4 RBS CD_D5 RRE AFTN Pa SE x L REB INT a MOUNT i RCB TI T gt OSCL CLKIN REL T RC _TX RTS _TXLRTS _TX2RTS _RXBBF Figure 2 3 CAN interface schematic Page 6 Microchip PIC16F876 Development Board User Manual kl Fi GI mann IRAI NWA OT PG N Figure 2 4 7 segment display schematic Page 7 Microchip PIC16F876 Development Board User Manual T1QUT T20UT RLIN R2IN ON OB GON be rz DO OD Figure 2 5 Serial interface schematic VOUT Figure 2 6 Temperature sensor schematic Page 8 Microchip PIC16F876 Development Board User Manual Power Supply NEB21R Figure 2 7 Power supply schematic l Goue 2 8 DENT HOES 8 QUNT HOLE2 8 OUNT HOLE 2 8 Ui n N r Figure 2 8 Power system schematics Page 9 Microchip PIC16F876 Development Board User Manual C Layout The board layout was done using the EAGLE automatic routing tool All of the components fit onto a two layer PCB smaller than a standard sheet of paper This layout is shown below in Figure 2 9 The Gerber files that were generated from this layout in order to fabricate the board are included in the PIC Development Board package k Bag a PETTE T T AL Le saoasnom K a ds SKI faa tin Tn
29. lications the railway industry and many other areas The CAN bus protocol can operate at speeds up to 1 Mbit per second has excellent error detection and correction capabilities and is very robust in poor electrical environments The PIC16F876 Development Board includes an interface for communicating with other devices over a CAN network This interface is comprised of the Microchip MCP2510 and the Philips PCA82C250 The MCP2510 is an 18 pin CAN controller that communicates with the PIC over its SPI serial interface This chip provides the logic necessary for receiving and transmitting messages over a CAN bus It includes three transmit and two receive buffers reducing the amount of management needed from the PIC This device interfaces with the CAN bus through another chip the PCA82C250 This chip provides the differential transmit and receive capabilities for the MCP2510 controller There are a few different resources for learning more about the CAN protocol The Microchip website has an application note AN713 that describes the basics of CAN Another introduction to the CAN protocol can be found at http www can cia de can protocol Page 13 Microchip PIC16F876 Development Board User Manual 7 segment LEDs The board includes four simple 7 segment LEDs for digital output These LEDs can be used for a variety of functions including a system clock a counter or any other application where some sort of digital feedback would be usef
30. ly This routine or at least the vital parts of it should be programmed into the PIC and performed every time the board is started to ensure proper operation It performs the following operations e selects the HS high speed crystal oscillator type e enables the power up timer disables the watchdog timer e disables low voltage programming e sets up the I O pins e configures the ADC analog to digital converter e turns the speaker on and emits a start up beep initializes and writes a test string to the LCD initializes and tests the 7 segment LEDs with a simple count down e reads the temperature and displays it on the LCD This code provides good examples of how the PIC accepts input from various devices on the board manipulates the data and sends output In particular it illustrates the usage of the ADC included in the PIC the speaker the LCD the temperature sensor and the 7 segment LEDs init c Initialization routine for PIC Board define PIC_XTAL 20MHz include lt pic h gt include delay h include mcp2510 h include lcd h include max7221 h HS oscillator Power up timer enabled Watchdog disabled Low voltage programming disabled __CONFIG HS amp PWRTEN amp BOREN amp WDTDIS amp LVPDIS define SPEAKER RC1 unsigned int READ_TEMPERATURE unsigned int x ADCONO 0x80 ADON 1 Turn ADC on DELAY_US
31. ment Board User Manual B Schematics amp Design Parts List At a physical level many components are needed in the board design to enable the functionality described in the previous section A complete listing of these components is given in Table 2 1 Every part required to build a PIC16F876 Development Board is included in this table Table 2 1 Design parts list NEIE E 20MHz 20MHz 20MHz CH 33uF RI TK oo C eNi CANConnetor Ra 120 ich 16F876 R 10 102 ME Ra io O PCA82C250 O R5 ik ICA IM R 100K ES Man RT ao IC6 _MAX7221 U 1 SPEAKERI IC7 LM78MO5 X1 Serial Connector IC7 _LM78M05 X1 Serial Connector Jl POWER lo Schematics and layout for the circuit board were done using CadSoft EAGLE The schematics on the following pages show the circuit diagrams for each of the major subsystems on the board Schematics are included for the following subsystems PIC16F876 Figure 2 2 CAN interface with the MCP2510 and the PCA82C250 Figure 2 3 7 segment LEDs including the MAX7221 display controller Figure 2 4 RS 232 serial interface using the MAX233A line driver receiver Figure 2 5 LM34 temperature sensor Figure 2 6 power supply and power system Figures 2 7 and 2 8 For descriptions of the operation of all of these subsystems please refer to Section 3 Board Operation For more detail on the design of the board please ref
32. mit Buffer 0 Control Register Transmit Buffer 0 Std Identifier High Transmit Buffer 0 Std Identifier Low Transmit Buffer 0 Ext Identifier High Transmit Buffer 0 Ext Identifier Low Transmit Buffer 0 Data Length Code Transmit Buffer 0 Data Byte 0 Transmit Buffer 0 Data Byte 1 Transmit Buffer 0 Data Byte 2 Transmit Buffer 0 Data Byte 3 Transmit Buffer 0 Data Byte 4 Transmit Buffer 0 Data Byte 5 Transmit Buffer 0 Data Byte 6 Transmit Buffer 0 Data Byte 7 Transmit Buffer 1 Control Register Transmit Buffer 1 Std Identifier High Transmit Buffer 1 Std Identifier Low Transmit Buffer 1 Ext Identifier High Transmit Buffer 1 Ext Identifier Low Transmit Buffer 1 Data Length Code Transmit Buffer 1 Data Byte 0 Transmit Buffer 1 Data Byte 1 Transmit Buffer 1 Data Byte 2 Transmit Buffer 1 Data Byte 3 Transmit Buffer 1 Data Byte 4 Page 22 define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define define Microchip PIC16F876 Development Board User Manual TXB1D5 0x4B Transmit Buffer 1
33. n in Section 4 Application Development Speaker The piezoelectric speaker provides rudimentary audio output for the board It interfaces directly with a single pin on the PIC The initialization routine in Section 4 Application Development includes a simple illustration of its use Voltage regulator The National LM78MO5 is a 3 terminal positive voltage regulator It regulates the voltage from the external power supply down to the 5V supply required by the board Page 14 Microchip PIC16F876 Development Board User Manual C Getting Input User input to the PIC can be provided by two possible means with the CAN interface or via the RS 232 serial port Both options allow the board to interface with a host of possible external devices One of the most convenient options is to connect the board directly to a personal computer with a serial cable Data can easily be sent to or received from the board using a program such as HyperTerminal These simple steps will enable the board to communicate with a Windows PC 1 Using a standard serial cable connect the board to the serial port on the back of your PC 2 Open HyperTerminal Start gt Programs gt Accessories gt Communications 3 The program should open a New Connection dialog box If not simply select that command from the File menu Enter a name for the connection 4 Specify COMI or whatever serial port the board is connected to in the Connect using drop down box
34. n in assembly or in another higher level language e g C The HI TECH Software ANSI C PICC Compiler has been obtained for use in the department and can be used for PIC software development for any Senior Design teams Information on the software modules included with the board and guidelines for developing your own software can be found in Section 4 Application Development Note This User Manual assumes that the reader has some background experience with microcontrollers and low level hardware software development The source code that was written for the development board is in C as well as all of the code examples All Senior Design students should have the knowledge necessary to understand and use this manual Page 3 Microchip PIC16F876 Development Board User Manual 2 Board Design A Functional Design From a functional perspective the board components are arranged as shown in Figure 2 1 The PIC is the centerpiece of the board and all other components communicate with the microcontroller The PIC accepts input from the RS 232 transceiver from the CAN interface and from the temperature sensor It can also send output to the RS 232 transceiver the CAN interface the speaker the 7 segment displays and the character LCD display CAN Interface RS 232 emperature Transceiver Sensor Character LCD Display Speaker 7 Segment Displays Figure 2 1 Functional block diagram Page 4 Microchip PIC16F876 Develop
35. oard was designed for the 16F876 a 28 pin PIC that should provide an appropriate level of performance and versatility for most design projects The board contains several useful components including e 28 pin ZIF zero input force socket to easily remove and replace the PIC e RS 232 serial port e CAN controller area network interface e 4 segment LEDs e 20x2 character LCD e temperature sensor e speaker e AC adapter for providing power to the board with a standard wall socket The schematics showing the connections of these components are given in Section 2 Board Design The operation of the development board and of each of these subsystems is described in detail in Section 3 Board Operation A PIC programmer can be purchased separately from the development board to program and re program code into the non volatile Flash memory of the PIC The P16PRO40 programmer was used in the development of this project Both the programmer and the development board have ZIF sockets for mounting the PIC allowing the user to easily swap the PIC between the two units Usage of the programmer is also described in Section 3 Board Operation Along with the board hardware software libraries have been written for each of the board components These libraries take care of the basic functionality for the hardware on the board allowing the user to concentrate on writing code for his or her specific application Software for the PIC can be writte
36. over SPI e SPI_SEND16 data Sends 16 bit uint data over SPI MSB gt LSB e SPI_RECEIVEI6 Returns 16 bit uint data received over SPI Page 20 Microchip PIC16F876 Development Board User Manual mcp2510 h Functions for using the MCP2510 CAN controller mcp2510 h Functions for using the MCP2510 on PICs k k Functions available ae CP2510_SETSPI x Sets up SPI port for use w the MCP2510 Ze CP2510_STATUS port mask Er Returns the MCP2510 status byte xk CP2510_WRITE port mask addr data EX Writes data to register at addr Er CP2510_WRITE_SEQUENCE port mask startaddr data len EX Writes data of length length starting at startaddr EK CP2510_READ port mask addr ER Returns data at register addr CP2510_RTS port mask rtsnum EK Request to send transmits packet rtsnum RTS0 RTS1 or RTS2 x CP2510_BITMODIFY port mask addr bitmask data KER Sets or resets data s bits in addr masked by bitmask KK MCP2510_RESET port mask Er A software reset of the MCP2510 KE CP2510_TRANSMIT_STD port mask id dlc data ER Transmit a standard data frame x CP2510_TRANSMIT_EXT port mask id eid dlc data Transmit an extended data frame xx CP2510_TRANSMIT_REM port mask id eid KR Transmit a remote data frame k k Variables port and mask are the data port and bitmask to fin
37. s for using the MCP2510 CAN controller e MCP2510_SETSPI Sets up SPI port for use w the MCP2510 e MCP2510_STATUS port mask Returns the MCP2510 status byte e MCP2510_WRITE port mask addr data Writes data to register at addr e MCP2510_WRITE_SEQUENCE port mask startaddr data len Writes data of length len starting at startaddr e MCP2510_READ port mask addr Returns data at register addr e MCP2510_RTS port mask rtsnum Request to send transmits packet rtsnum RTSO RTS1 or RTS2 e MCP2510_BITMODIFY port mask addr bitmask data Sets or resets data s bits in addr masked by bitmask e MCP2510 RESET port mask A software reset of the MCP2510 e MCP2510_TRANSMIT_STD port mask id dlc data Transmit a standard data frame e MCP2510 TRANSMIT EXT port mask id eid dlc data Transmit an extended data frame e MCP2510_TRANSMIT_REM port mask id eid Transmit a remote data frame lcd h Functions for controlling and sending output to the LCD e LCD OUT COMMANDI unsigned char cmd Sends a command byte to the LCD e LCD OUT UPPER NYBBLE unsigned char nybble Sends a command nybble 4 bits to the LCD e LCD CLEAR Clear the display Page 18 Microchip PIC16F876 Development Board User Manual LCD_HOME Home the cursor LCD_SET_CGRAM x Set the CGRAM to x LCD_SET_DDRAM Set the DDRAM to x LCD_OUT_DATA unsigned char data Sends a data byte to the LCD LCD_INITIALIZE unsigned char lines Initializes the display LCD_PUT
38. ternet that introduce beginners to the basics of using the PIC Some of these sites are listed in Section 5 Additional Resources RS 232 serial port RS 232 is a standard bus protocol used for serial communications most notably for communicating with personal computer serial ports The PIC16F876 Development Board includes a RS 232 port for communicating with a computer or any other device that communicates via RS 232 In this way a program such as HyperTerminal could be used to provide input to the PIC when connected to a computer via a standard serial cable Another possible use might be to connect a serial keyboard to the board as another means of providing input The PIC is able to communicate via RS 232 through the on board MAX233A serial transceiver This device connects to the serial port and generates and receives the signals used in the RS 232 protocol It also provides the conversion from the board s 5V power supply to the 12V needed to communicate with RS 232 The MAX233A is sold by Maxim and its data sheet can be found at http www maxim ic com The website also includes several application notes about working with the RS 232 protocol CAN interface CAN Controller Area Network is a serial bus protocol that is widely used in real time control applications It was originally developed for use in automotive electronics systems but its use has since extended to machine automation and control building automation medical app
39. tor multiple project workspaces breakpoints etc The PICC C compiler from HI TECH Software is the most readily available package for C programming for the PIC This compiler supports full ANSI C with the exception of recursion the PIC s stack is to small to support this It is also fully compatible with the MPLAB IDE for easy integration of C and Assembly code This software package which normally costs near 1000 is available for free student use in the Senior Design lab Once the source code in either Assembly or C has been compiled and assembled into hex data it is ready to be programmed into the PIC This can be done using the procedure previously described in Section 3 D PIC Programming Page 17 Microchip PIC16F876 Development Board User Manual B Software Libraries Software libraries have been written to provide basic functionality for the CAN controller the LCD the 7 segment displays and the RS 232 serial port There are also libraries that implement delays for proper timing and configure the SPI port on the PIC The next few pages of this manual contain the source code for these libraries These libraries can simply be included as a header file in any C code that is written for applications using these devices The functions included in each of these libraries are briefly described here The comments within the source code should be sufficient to determine how to properly use these functions mcp2510 h Function
40. ul They are controlled with the Maxim MAX7221 LED display driver Like the CAN controller it communicates with the PIC using an SPI serial interface This device is a common cathode display driver that operates serially at 10 MHz It includes a number of features for easy and flexible control of the LEDs More detailed information on this device can be found in its datasheet and supporting documentation at http www maxim ic com Character LCD The character LCD is a standard display that is capable of providing two rows and twenty columns of standard ASCI text This device interfaces directly with the PIC using seven of the microcontroller s pins Software libraries allow the user to easily initialize the display clear the display write a single character write a string and send other commands to control the display s operation More information on using the LCD is given in Section 4 Application Development Temperature sensor The National Semiconductor LM34 is a precision temperature sensor Its output is calibrated to be linearly proportional to degrees Fahrenheit at a scale factor of 10 0 mV deg F It is rated over a very wide range of 50 to 300 deg F enabling its use in a wide variety of applications This device interfaces directly with one I O pin on the PIC The voltage input from the temperature sensor can be converted to a digital value using the PIC s ADC An example of its use is included in the initialization routine give

Download Pdf Manuals

image

Related Search

Related Contents

Istruzioni per l`uso  2014 Chevrolet Silverado and GMC Sierra…  Engine Transverse Bar w/Support Arm Operating Instructions  LP612 and LP624 User`s Manual Leprecon/CAE, Inc  DAIKEN クローゼットの取扱い  

Copyright © All rights reserved.
Failed to retrieve file