Home

Arizona Picdem 17 User's Manual

image

Contents

1. EV SV 4 U6 Nc RESETA 44 ham C26 U4 C25 US Zen VEIL En A 4 Er BI 20 Cala 20 e i m m 42 Ka vcc vec 2 IAS A1 ja Jo Jan alt A12 35 Kei ra Td Es MIHL D 11 11 LENS ATUS En ye tk A ZG DEE E Zil a ka 2 19 2 19 14 VSS Mel 31 eD 00 e 00 D0 00 CT 15 JOE DO15 A 1 3 En HE eo 01H e E 16 red Ba 2 as e Cami lm amp i io cotte ps ol er a os m z Daz E 2 G3 Blo usm pm bts ian ZS 22 005 CG T ls es as ies os ei Bloe at ge aLe os eo AM29F 100 Jeza 9107 o mei Bin vH bie 18 em 18 no 74ACT573 gt 74ACT573 T gt 5V E LCD D1 Togo 08118 ES No oy RB e 082 9 470 be 10K es 08319 C27 U8 rs LCD 2X8 oa Be PNE Doo 3e ces 12 ep GE P s dy if 5V 2 veo Des 13 gp E34 E En R7 Ts e LE Se D7 820 le L Pod 4 53 oHe 470 An 01118 LED 4 17 e RN5 4 DE 5 D3 03 16 8 7 i A C23 Ep 15 470 E D4 04 LED Es oer tuF Hos os 13 aBN6 1 Di 9 12 7 o7 470 is Lee vec Am je D10 pend aura IGND ANSE ay 4 OSC CAN 74ACT573 470 Kai LED x D11 eBN6 3 oy 470 Ge AVDD RNG 4 D U14 8 AT d uF U15 5V 470 LP2950ACZ 5 0 T LED 2 our H 4 Lun vor e cou JP2 C33 EN R14 o 92 ka 3MAX6 141 4 7K r 220uF S1 Li R15 161041 ANA En ZO os 470 NZ Mv C11 i D2 VRT 1 1 uF JI LM3407 5 0 4 UM our FS i C3 3 X 2 ce St ca ES 0 1uF 01
2. 0000000 GA 6 0 6 0 6 0 6 06 6 0 6 0 A15 8r07 00000 D qmeeeeee Os s11 S19 S9 S8 S7 S6 S5 maoe ceeeeee reseso OOOO Fe ee Nee REE R8 R7 A12 0 RD4 V 019 pia et St oS F O A11 rDs e A1D eRrD2 60000000 909000000098 00000060 ee Rt e RN6 Ri RN5 A700RC7 e C24 A6 RC6 Aseenc e ss B oe sme eei is 9 e a B ZZ 8 O mun i2een e e e e e e e o E e e e e C E o o o e leesc je e e e e e e o e m oeenco e o o je e e o o m RE200RE e e e e eae eis n Legere e e e o e je e e U16 s SG eene 3838 Bol SNS es o sS E NUS m m 0 EU EU C36 RJ40 RCZ e ue RJ3ee s N Se EM E RJO e RB4 PICDEM 17 DEMO BOARD A Meri le MCLR RHeleens IR 04 01519 Rev 4 c MICROCHIP Mees EN C20 e RH4 0 RBO ce MO RI4 PIC17C76X RH3I IRAS Se OM rs a z RH200Ra 9 PIC17C75X 00000000000 RH1 RS 000 0000000000000 RHO RA2 02 c32 ee 000000000 ee ee RE3 6 RA1 00000000000 C14 c19 ee ee LE 1 9 0 540 e e ee le ee ee e eo ee e ee ee e eo ee e le eo ee SDA j4 eo ee eo ee ee SCL ce 00000000000 0000000000000 SK eo 000000000 00000000000 SDO o ee D a SDI o ce a cs e ee RF6 eo RF7 C12 C13 ee Rce SDA ee ee RG1 633 o sc qe eo RH4 ji CANH H RHS M CANL ERE RO DL Pe Seria ca C3 gt e U15 Besssesesses De a eo o Umace o e e DRE nw J B e Rei 0 00000
3. Filename xlcd h Date 14 April 1998 File Version 2 10 KKAKKAKKAKAKAKAAKAKAKAAKAAKAAAKAAKAKAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKk Functions Header file KKAKAKKAKAKAKAKAKAKAAKAAAAAAKAAAAKAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Revision History V1 00 Beta release of Peripheral Libraries for V1 21 V2 00 Release of Peripheral Libraries for V2 00 V2 10 Release of Peripheral Libraries for V2 10 Added putrsXLCD to output strings in ROM to XLCD KKAKAKAKAAKAAKAAAAKAAAAKAAKAAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK Notes ROM usage varies depending on specified device These libraries routines are written to support the Hitachi HD44780 LCD controller The user must define the following items The LCD interface type 4 or 8 bits If 4 bit mode whether using the upper or lower nibble The data port The tris register for data port The control signal ports and pins The control signal port tris and pins The user must provide three delay routines DelayFor18TCY provides a 18 Tcy delay DelayPORXLCD provides at least 15ms delay DelayXLCD provides at least 5ms delay AAT ifndef XLCD H define XLCD H E EE E E EE E EE E EE E E EE Interface type 8 bit or 4 bit For 4 bit operation comment out the define BIT8 define BIT8 When in 4 bit interface define if the data is in the upper or lower nibble For lower nibble comment out
4. movlw HIGH _start movwf PCLATH moviw LOW start movwf PCL pOKCkCkckckcsk RRR KR kc ec ke ke cec ke ke e ke ke e he ke ke e he ke ke he ke ee he ke ke che he ke ce he ke ke che he ke ehe he ke e e he e k Start section CODE Beginning of startup code start Optionally call the routine that copies initlialized data from program memory to data memory i IFDEF USE INITDATA movlw HIGH copy init data movwf PCLATH lcall copy init data ENDIF Set up the stack for use with function arguments and local auto variables Setup stack BANKSEL stack Switch to bank where the stack pointer is movlw _stack 2 Store the address of the stack pointer 2 movwf stack Into the stack pointer movlw HIGH main movwf PCLATH movlw LOW main movwf PCL 2001 Microchip Technology Inc DS39024B page 27 PICDEM 17 Demonstration Board User s Guide 4 5 Interrupt Code File The interrupt code file is used to setup the interrupt vectors for the INT pin TMRO Overflow TOCKI pin and the Peripheral Interrupt vector Included with this code is the context save and restore routines that are called before and after the interrupt service routines The real interrupt vectors of the PIC17C756A located at addresses 0008h 0010h 0018h and 0020h have been remapped to address location 4008h 4010h 4018h and 4020h The original vectors have code that simply writes the associated vector address of 40 h to t
5. 2001 Microchip Technology Inc DS39024B page 1 PICDEM 17 Demonstration Board User s Guide Chapter 8 SWITCH C Description This chapter provides a detailed description of the memory mapping of the PIC17C756A and provides source code to interface to the memory mapped switches and LEDs Chapter 9 12c c Description This chapter provides a detailed description of the demonstration program for the PIC17C756A that reads and writes data from a 24LC01B Serial EEPROM Appendix A PICDEM 17 Demonstration Board Schematics This appendix provides the PICDEM 17 demonstration board parts layout diagram and the board schematics Appendix B RS 232 Communication Protocol This appendix provides the protocol for the PIC17C756A Monitor firmware to communicate to the PC based software Appendix C Floppy Disk Contents This appendix contains a listing of all files on the included 3 5 inch floppy disk There is also a description as to the use of each file when compiling programs for the PICDEM 17 demonstration board and the PIC17C7XX microcontrollers Appendix D On line Support This appendix provides information on Microchip s electronic support services Worldwide Sales amp Service This reference gives the address telephone and fax numbers for Microchip Technology Incorporated sales and service locations throughout the world DS39024B page 2 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MI
6. Update switch state buffer SWTbuf TEMPbuf Wait for 16ms Delay1KTCYx 64 MALEN DS39024B page 68 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 9 12C C Description 9 1 Introduction This chapter describes the demonstration program for the PIC17C756A I2C C This program takes an incrementing count and writes it to the 24LC01B Serial EEPROM and displays the address on the memory mapped LEDs This program also displays the desired value and the actual value for each location Before running this program make sure that S3 positions 1 and 2 are ON and the rest are OFF 9 2 Highlights This chapter covers the following topics MPLAB IDE Project Files PICmicro C Libraries Source Code Descriptions I2C C Source CodeListing 9 3 MPLAB IDE Project Files The project I2C PJT contains the following files I2C PJT DEMO756L LKR m P17C756 0 PMC756L LIB COL17DEM O d26 C The files in this project use the following header files P17C756 H DELAYS H 2001 Microchip Technology Inc DS39024B page 69 PICDEM 17 Demonstration Board User s Guide 9 4 PICmicro C Libraries The files in I2C PJT use the following library function s contained in PMC756L LIB DelaylKTCYx 9 5 Source Code Descriptions DEMO756L LKR P17C756 0 PMC756L LIB COL17DEM O I2C C P17C756 H DELAYS H This fi
7. 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 4 Using the MPLAB C17 C Compiler 4 1 Introduction This chapter describes the files necessary to compile programs with the MPLAB C17 C compiler to run on the PICDEM 17 demonstration board A sample linker script file DEMO756 LKR is described as well as other support files 4 2 Highlights This chapter covers the following topics Linker Script File DEMO756 LKR Startup Code File COL17DEM ASM Interrupt Code File INT756LD ASM Other Files Note 1 User should refer to MPLAB IDE document that shows project setup but special version of linker scripts etc are used here because of the demonstration board requirements 2 Also refer to the MPLAB C17 C Compiler User s Guide DS51112 for additional information 2001 Microchip Technology Inc DS39024B page 23 PICDEM 17 Demonstration Board User s Guide 4 3 Linker Script File Any program compiled with the MPLAB C17 C compiler requires the use of a linker script file that documents the areas of memory that the linker is free to use Programs targeted to run out of external FLASH program memory require a special linker script file that assumes that program memory starts at address 4000h All of the source code written for the PICDEM 17 demonstration board must be compiled using the large memory model since it will reside at memory addresses larger than 4000h and will be called from a me
8. DS39024B page 86 2001 Microchip Technology Inc
9. If this diagnostic is selected and these I O pins are not connected to the LCD panel then the message will not be displayed correctly Provided the connections are correct the diagnostic does not require any interac tion from the user PWM This diagnostic allows the user to select the PWM channel and increment or decrement the period and duty cycle of that channel During PWM Diagnostics the switches and LEDs take on the following functions S5 Increments the channel 1 3 only S7 Decrement the duty cycle down to 0 S8 Increment the duty cycle no upper limit S9 Decrement the period down to 0 10 Increment the period no upper limit 12 Selects clock source Timer1 or Timer2 D1 D6 PWM channel D12 Timer source Timer1 OFF or Timer2 ON The diagnostic ends when Halt is clicked Switches This diagnostic tests the functionality of the memory mapped switches and LEDs Each time a switch is pressed the corre sponding LED is turned OFF This diagnostic ends when all LEDs have been turned OFF USART2 This diagnostic writes a message to the Monitor program running on the PC Host This diagnostic does not require any interac tion from the user To run a diagnostic highlight the desired test in the Diagnostics window of the Monitor program Then click the Execute button to start the test Those tests that do not automatically terminate can be stopped using the Stop button DEEN DS39024B page 12 2001 Microchip
10. 1 5 Memory Mapping Since the PIC17C756A is in the extended microcontroller mode there are several memory mapped peripherals available to the user The first is the eight push button switches mapped at address FFFCh The eight LEDs are mapped at address FFFDh There are also two signals that provide decoding for an address of 8 LE 1 and an address of 16 LE 2 These signals are located in the digital prototyping area in the upper right hand corner of the board 1 6 Power Supply The PICDEM 17 demonstration board provides a different power supply structure to the user The only power input capable of powering the entire board is at the connector J1 Any power supply with a 2 1 mm plug capable of delivering 9V up to 1A unregulated Alternating Current AC or Direct Current DC can be used The digital components on the board are powered from a LM2940T 5 0 that is capable of supplying 1A of current This digital 5V is available in the digital prototyping area in the upper right hand corner of the board The analog section of the PICDEM 17 demonstration board has a separate power source and voltage reference A LM78L05 5V regulator provides 150 mA at 5V for the analog circuits It is also available in the analog prototyping area in the lower left hand corner of the board There is also a precision 4 096V reference that is connected to the Analog to Digital A D as well as the analog prototyping area 1 7 Prototyping Areas The PICD
11. ANALOG C Description 7 4 ANALOG C Source Code Listing LL BRR RK ok kok ok kok ok IR RR RR RR RR kk oko TOR ko k k k ke eek eee ANALOG C LL BRK RR ok kok ok kok ok RR oko TOR oko TR oko oko oko TOR ke eee ee Rodger Richey Principal Applications Engineer Microchip Technology Incorporated LL BRR RRR ok kok ok kok ok IR TOR TR TR TR TR k k k TOR TOR k k k k K K K eee 2 December 1998 Compiled using MPLAB C17 C Compiler V2 20 J BRR RR RK KK RAR RR RAR RR RR RR RR RRA RRA k k k RRA This program performs an A D conversion on CH2 and prints the result in ASCII to USART2 which displays the result on the Monitor program LL BRK RR RK ok kok KK RR TR TOR TTR TOR Re Uses an oscillator of 16MHz J RRR RRR k k k k k k k KR KKK k k k KR KKK k k k k KKK k k k k KKK k k KK KK KR k k RK KK include lt p17c756 h gt include lt delays h gt include lt usart16 h gt include lt stdlib h gt include lt adc16 h gt void PutsUSART2 char data Prints a string to USART2 using hardware handshaking void PutsUSART2 char data do Wait for the USART to finish prev operation while BusyUSART2 Wait for CTS while PORTBbits RB4 Print character to USART2 putcUSART2 data while data Increment pointer and check for NULL return void main void unsigned int result char str 7 char crlf 3 Initialize the carriage re
12. PMC756L LIB COL17DEM O ANALOG C The files in this project use the following header files P17C756 H DELAYS H USART16 H STDLIB H ADC16 H 2001 Microchip Technology Inc DS39024B page 61 PICDEM 17 Demonstration Board User s Guide 7 2 PlICmicro C Libraries The files in ANALOG PJT use the following library function s contained in PMC756L LIB DelaylOKTCYx BusyUSART2 putcUSART2 OpenUSART2 OpenADC ConvertADC BusyADC ReadADC uitoa 7 3 Source Code Descriptions DEMO756L LKR P17C756 0 PMC756L LIB COL17DEM O ANALOG C P17C756 H DELAYS H USART16 H STDLIB H ADC16 H This file is the linker script file for the project This file contains the processor dependent objects it is included by the linker script file This file contains the library functions compiled for large memory model it is included by the linker script file This fwwile contains the startup code to initialize the Stack initialize data call the startup function and jump to main This file is the main source code file for the project This header file contains processor specific items This is the header file for delay routines in the library This is the header file for the USART routines in the library This is the header file for standard library routines This is the header file for A D routines in the library DS39024B page 62 2001 Microchip Technology Inc
13. Wait if LCD busy WriteCmdXLCD 1cdtype Function set cmd Turn the display on then off while BusyXLCD Wait if LCD busy WriteCmdXLCD DOFF amp CURSOR OFF amp BLINK OFF Display OFF Blink OFF while BusyXLCD Wait if LCD busy WriteCmdXLCD DON amp CURSOR ON amp BLINK ON Display ON Blink ON Clear display while BusyXLCD Wait if LCD busy WriteCmdXLCD 0x01 Clear display Set entry mode inc no shift while BusyXLCD Wait if LCD busy WriteCmdXLCD SHIFT CUR LEFT Entry Mode Set DD Ram address to 0 while BusyXLCD Wait if LCD busy SetDDRamAddr 0 Set Display data ram address to 0 return te Function Name WriteCmdXLCD Return Value void Parameters cmd command to send to LCD Description This routine writes a command to the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine KKAKAKKAKAKAKAKAKAAAAAAAAKAAAKAAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk void WriteCmdXLCD static unsigned char cmd DS39024B page 46 2001 Microchip Technology Inc LCD C Description while BusyXLCD ifdef BIT8 8 bit interface TRIS DATA PORT 0 Data port output DATA PORT cmd Write command to data port RW PIN 0 Set the control signals RS PIN 0 for sending a com mand DelayForl8TCY E
14. define LINE 5X10 0500110111 5x10 characters define LINES 5X7 0500111111 5x7 characters multiple line Other Functions define CLS 0b00000001 Clear display Set DDRAM to 0 define HOME 0b00000010 Set DDRAM to 0 void OpenXLCD static unsigned char Configures I O pins for external LCD void SetCGRamAddr static unsigned char Sets the charac ter generator address void SetDDRamAddr static unsigned char Sets the display data address unsigned char BusyXLCD void Returns the busy status of the LCD unsigned char ReadAddrXLCD void Reads the current address char ReadDataXLCD void Reads a byte of data void WriteCmdXLCD static unsigned char Writes a command to the LCD void WriteDataXLCD static char Writes a data byte to the LCD define putcXLCD WriteDataXLCD a putc is a write void putsXLCD static char Writes a string of characters DS39024B page 40 2001 Microchip Technology Inc LCD C Description to the LCD void putrsXLCD static const rom char zi Writes a string of characters in ROM to the LCD User defines these routines according to the oscillator frequency extern far void DelayFor18TCY void extern far void DelayPORXLCD void extern far void DelayXLCD void Hendif Hpragma list O 2001 Microchip Technology Inc DS39024B page 41 PICDEM 17 Demonstration Board User s Guide 5 7 XLCD C Source
15. gt S dada Nasa ma J SR AR gg eeeeePee P8282 28 SBR se elen Rus 4 p RES RH RJ4 235 p EF roi RAD 22 uo RY Roo R80 Ho RE reo RB1 72 Cx 17 RE re3 6 fas E ees RB4 88 m ei re3 Res BI f ai MR e RB2 9 pr 21 hesr 17C766TH m Z2 NC ncl64 q hss osc 83 45V 24 on osc1 92 fr col SZ ra RF6 RB7 Sak 27 legs RBB 59 C15 Ze sote lur 29 er Raz 97 je z 30 er aal m 31 eu R3 Pe 32 nus RJ2 54 o Or a H NN mo 0 N t amp E 2 2 9 eae 4 8 see 2 2 o 3 3 4 8 5 4 4 Y SN SI 2 8 FF o RH6 El L Reo Roe Ke Res Gal bei AVDD H HI 5v C17 C18 0 1uF 0 1uF N7 2001 Microchip Technology Inc DS39024B page 77 PICDEM 17 Demonstration Board User s Guide A3 SCHEMATIC 3 C7 1uF 406 su TUF 4 2 o 3 T i 74ACT573 Holon gt c S11 Lo o3 Sit R12 y Lo ot 4 7K s2 L6 os PEN Ho SE GIE U16 m rend 5V MS 0 1ul vx vora gt Ziwe c36 Zum voan EH E ans vorei PROTOTIPE AREA Gm vo os 24 f
16. large memory model it is included by the linker script file COL17DEM O This file contains the startup code to initialize the stack initialize data call the startup function and jump to main LCD C This file is the main source code file for the project XLCD C This file contains the source code to interface to the external LCD display P17C756 H This header file contains processor specific items DELAYS H This is the header file for delay routines in the library XLCD H This is the header file for the external LCD routines in XLCD C E E o o_o oQRD gt rrroooooQoQqoDR E n o DS39024B page 36 O 2001 Microchip Technology Inc LCD C Description 5 5 LCD C Source Code Listing LL BRR RR ok kok ok kok ok IR kok ok TR TR TR TR TCR TOR TTR TOK ke LCD C AAA Rodger Richey Principal Applications Engineer Microchip Technology Incorporated LL BRR RR RK ok kok ok TR TOR TR TR TR TR RARA RRA k k k RRA 2 December 1998 Compiled using MPLAB C17 C Compiler V2 20 J BRR RRR RR RR RR RR RR RRA RRA RRA RR RR RRA k k k RRA RRA This program displays a message on a LCD display that uses the Hitachi HD44780 controller or ZE equivalent The first line shows Hello and the second line shows World LL BRR RR ok kok ok kok ok IR kok ok TOR TTR TR TR TOR Re Uses an oscillator of 16MHz J RRR RRR k k k k k RK k KR KKK k k KR KKK RK k k KKK k k k k k k k k KK KR KR
17. 12 The clock source Fosc 8 Fosc 32 Fosc B4 FRC D1 D6 D8 Channel number in HEX format D9 Internal OFF or External ON voltage references D10 Left OFF or Right ON justify D11 D12 A D clock source The diagnostic ends when Halt is clicked Capture The capture diagnostic allows the user to configure the capture channel and mode The capture results are displayed in the Monitor message window During Capture Diagnostics the switches and LEDs take on the follow ing functions S5 Increment capture channel 1 4 only S9 Increment toggle mode D1 D6 Capture channel D9 D10 Capture mode The diagnostic ends when Halt is clicked FLASH The external FLASH memory diagnostic simply writes all zero s all one s checkerboard and inverse checkerboard to a portion of memory and checks to make sure that the values were properly written This diagnostic does not require any user interaction IPC This diagnostic writes an incrementing count to the 24LC01B Serial EEPROM on the PICDEM 17 demonstration board and verifies that each location has been properly programmed This diagnostic does not require any interaction from the user 2001 Microchip Technology Inc DS39024B page 11 PICDEM 17 Demonstration Board User s Guide e LCD This diagnostic configures I O pins and writes a message to the external LCD panel in 4 bit mode portF 0 3 data lines portG 1 E portG lt 0 gt R W portF lt 7 gt RS
18. 70 1900 Source Godella iio teca 71 Appendix A PICDEM 17 Demonstration Board Schematics A 1 A 2 A 3 A 4 eppure E 76 Ss A laica O TN 77 AN dee Da Dx 78 Seer ANC ul LL E 79 2001 Microchip Technology Inc DS39024B page 5 PICDEM 17 Demonstration Board User s Guide Appendix B RS 232 Communication Protocol A is BEE 81 Bee EA E A E E 81 ES Detailed DescrlpllOli ico oe aia acids 81 Appendix C Floppy Disk Contents C1 IntrOdACHON BEE 83 Ou CONC ee 83 Worldwide Sales and Service 86 DS39024B page 6 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE PREFACE Welcome Thank you for purchasing the PICDEM 17 product demonstration board for the PIC17C7XX family of microcontrollers from Microchip Technology Incorporated The PICDEM 17 demonstration board allows you to quickly and easily become familiar with both the PIC17C7XX products and the MPLAB9 ICE in circuit emulator The PICDEM 17 demonstration board currently supports all 68 pin and 84 pin PLCC products The software provided with the PICDEM 17 demonstration board for the PIC17C7XX Monitor runs under Microsoft Windows 95 only Documentation Layout This document describes the PICDEM 17 demonstration board A detailed description of the demonstration software is also provided to give the user an overview of the PIC17C7XX series of PICmicro MCUs Detailed usage of the microcontrollers MPLAB IDE or M
19. Code Listing include lt p17cxx h gt include xlcd h ck ck ke ck e KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KKK KEK AAA AAA AAA ck kc ko K PICmicro C Libraries V2 10 Written and Tested using MPLABC V2 10 KKAKAKAKAAKAAKAAKAAAAAAAAKAKAKAKAKAKAKAKAKAKKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAXk kk Filename xlcd c Date 14 April 1998 File Version 2 10 kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk Kk Functions void OpenXLCD unsigned char lcdtype void SetCGRamAddr unsigned char CGaddr void SetDDRamAddr unsigned char DDaddr unsigned char BusyXLCD void unsigned char ReadAddrXLCD void char ReadDataXLCD void void WriteCmdXLCD unsigned char cmd void WriteDataXLCD char data void putsXLCD char buffer void putrsXLCD const rom char buffer KKAKAKAKAKAKAAAAKAAKAAAAKAAKAKAKAKAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAXk HO E Kk Revision History V1 00 Beta release of Peripheral Libraries for V1 21 V2 00 Release of Peripheral Libraries for V2 00 V2 10 Release of Peripheral Libraries for V2 10 KKAKAKKAKAAAAAAAAAAAAAAAKAKAKAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk Kk Notes ROM usage varies depending on specified device KKAKAKAKAAKAKAAAKAAAAAAKAAKAKAKAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAX KKAKAKAKAAAKAAAAAAAAAAAAAKAKAKAKAKAKAKKAKKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKk
20. Demonstration Board User s Guide NOTES DS39024B page 34 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 5 LCD C Description 5 1 Introduction This chapter describes the demonstration program for the PIC17C756A LCD C This program takes an incrementing count and displays it on an external LCD panel using the interface provided on PICDEM 17 demonstration board Highlights This chapter covers the following topics MPLAB IDE Project Files PICmicro C Libraries Source Code Descriptions LCD C Source Code Listing XLCD H Source Code Listing XLCD C Source Code Listing 5 2 MPLAB IDE Project Files The project LCD PJT contains the following files LCD PUT DEMO756L LKR m P17C756 0 PMC756L LIB COL17DEM O LCD C L XLCD C The files in this project use the following header files P17C756 H DELAYS H XLCD H 2001 Microchip Technology Inc DS39024B page 35 PICDEM 17 Demonstration Board User s Guide 5 3 PlCmicro C Libraries The files in LCD PJT use the following libray function s contained PMC756L LIB Delayl0TCY Delay1KTCYx 5 4 Source Code Descriptions DEMO756L LKR This file is the linker script file for the project P17C756 0 This file contains the processor dependent objects it is included by the linker script file PMC756L LIB This file contains the library functions compiled for
21. PIN 1 Clock the command in DelayForl8TCY E PIN 0 DelayForl8TCY TRIS DATA PORT Oxff Data port input else 4 bit interface ifdef UPPER Upper nibble interface TRIS DATA PORT amp OxO0f DATA PORT amp Ox0f DATA PORT cmd amp 0xf0 else Lower nibble interface TRIS DATA PORT amp 0xf0 DATA PORT amp Oxf0 DATA PORT cmd gt gt 4 amp 0x0f endif RW_PIN 0 Set control sig nals for command RS_PIN 0 DelayFor18TCY E PIN 1 Clock command in DelayForl8TCY E PIN 0 ifdef UPPER Upper nibble interface DATA PORT amp OxO0f DATA PORT cmd lt lt 4 amp 0xf0 else Lower nibble interface DATA PORT amp Oxf0 DATA PORT cmd amp 0x0f endif DelayFor18TCY E PIN 1 Clock command in DelayForl8TCY E PIN 0 ifdef UPPER Make data nibble input TRIS DATA PORT 0xf0 else TRIS DATA PORT 0x0f endif endif return 2001 Microchip Technology Inc DS39024B page 47 PICDEM 17 Demonstration Board User s Guide EEN Function Name SetCGRamAddr Return Value void Parameters CGaddr character generator ram address Description This routine sets the character generator address of the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine KKAKAKAKAKAAAAAAAAAAAAAKAAKAKAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKK
22. RETFIE TMRO prolog DS39024B page 30 2001 Microchip Technology Inc Using the MPLAB C17 C Compiler Save BSR and WREG movfp BSR PCLATH CITE BSR 1 movpf PCLATH save BSR Service the interrupt by calling the interrupt handling function goto TMRO 2 _TMRO_1 BANKSEL fpTMRO movfp fpTMRO 1 PCLATH movfp fpTMRO PCL _TMRO 2 call _TMRO_1 push address of next instruction on stack Restore WREG and BSR clrf BSR 1 BSR was saved in bank 0 movfp save BSR BSR Now restore it movfp save WREG WREG and WREG as well Restore PCLATH and ALUSTA movfp save PCLATH PCLATH movfp save ALUSTA ALUSTA Return from interrupt RETFIE TOCKI prolog Save BSR and WREG movfp BSR PCLATH clIrf BSR 1 movpf PCLATH save BSR Service the interrupt by calling the interrupt handling function goto TOCKI 2 TOCKI 1 BANKSEL fpTOCKI movfp pTOCKI 1 PCLATH movfp fpTOCKI PCL _TOCKI 2 call TOCKI 1 push address of next instruction on stack Restore WREG and BSR clrf BSR 1 BSR was saved in bank 0 movfp save BSR BSR Now restore it movfp save WREG WREG and WREG as well Restore PCLATH and ALUSTA movfp save PCLATH PCLATH movfp save ALUSTA ALUSTA Return from interrupt RETFIE 2001 Microchip Technology Inc DS39024B page 31 PICDEM 17 Demonstration Board User s Guide _PIV_prolog Save BSR and WREG movfp BSR PCLATH CIrf BSR 1 movpf PCLATH save BSR Service the interrupt
23. T 02 E 5S E ZT 220uF Jew 220uF 470 DI 2001 Microchip Technology Inc DS39024B page 79 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 80 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Appendix B RS 232 Communication Protocol B 1 INTRODUCTION This appendix describes the protocol between the PIC17C756A microcontroller and the Host PC B 2 OVERVIEW The PICDEM 17 Monitor program and associated firmware in the PIC17C756A communicate via a RS 232 link between the serial port on the PC and the USART2 module on the PICmicro MCU The format is 9600 baud no parity 8 data bits and 1 stop bit The protocol itself is plain ASCII text which means that any terminal program can be used to communicate with the firmware The Monitor program was developed as a convenience to the user When using a terminal program the H command will display all the available commands to the user Descriptions of the operation of the diagnostics are given in Chapter 2 B 3 DETAILED DESCRIPTION The following are all the commands and associated descriptions e A e DA e DC e DF e DI e DL RDbxx Rpyyyy WDbxxdd WPyyyydddd Halt Operation A D Diagnostic Capture Diagnostic Flash Diagnostic DC Diagnostic LCD Diagnostic PWM Diagnostic Switch Diagnostic USART2 Diagnostic Erase FLASH Download File Print Help Run Progra
24. Technology Inc Using the PICDEM 17 Monitor PICDEM 17 Monitor v1 00 ix Source file filename Download Erase Run Reset J Diagnostics eum NC Flash lec Stop PWM Switches zi Modify memory Data memory ALES q C Program memory Value 0 Read Write p Messages Boot Mon v1 01 00 2 DA Lal Figure 2 5 Running Diagnostics 2001 Microchip Technology Inc DS39024B page 13 PICDEM 17 Demonstration Board User s Guide 2 10 Modifying Memory Contents The PICDEM 17 Monitor program has the capability to read from any Data memory location or internal external Program memory location It can also write to any Data memory location and any external FLASH program memory location Writes to internal program memory are not allowed because this memory is EPROM based PICDEM 17 Monitor v1 00 zix Source file filename Download Erase Pun Rest Diagnostics Execute Capture Flash lec Stop PWM Switches E Modify memory Data memory Address Jo C Program memory Value fo Write Messages Boot Mon vi 01 00 gt AD011 DF gt ld Figure 2 6 Reading Data Memory To read from a Data memory location the user must first select the Data Memory radio button in the Modify Memory window of the Monitor program Then the Data memory address must be written into the Address edit b
25. amp 0xf0 DATA PORT amp Oxf0 DATA PORT data gt gt 4 amp 0x0f endif RS_PIN 1 Set control bits RW_PIN 0 DS39024B page 54 2001 Microchip Technology Inc LCD C Description DelayFor18TCY E PIN 1 Clock nibble into LCD DelayFor18TCY E PIN 0 ifdef UPPER Upper nibble interface DATA PORT amp Ox0f DATA PORT data lt lt 4 amp 0x 0 else Lower nibble interface DATA PORT amp Oxf0 DATA PORT data amp 0x0f endif DelayForl8TCY E PIN 1 Clock nibble into LCD DelayForl8TCY E PIN 0 ifdef UPPER Upper nibble interface TRIS DATA PORT 0xf0 Helse Lower nibble interface TRIS DATA PORT 0x0f endif Hendif return 2001 Microchip Technology Inc DS39024B page 55 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 56 2001 Microchip Technology Inc AN PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 6 USART C Description 6 1 Introduction This chapter describes the demonstration program for the PIC17C756A USART C This program takes an incrementing count and displays it on the Monitor program using USART2 and hardware handshaking 6 2 Highlights This chapter covers the following topics MPLAB IDE Project Files PICmicro C Libraries Source Code Descriptions USART C Source Code Listing 6 3 MPLAB IDE Project Files The project
26. che he ke khe he ke e e he e e _TOCKI sec CODE H 4018 Save ALUSTA movpf ALUSTA save ALUSTA must save ALUSTA before others movpf WREG Save WREG temporarily save off WREG 2001 Microchip Technology Inc DS39024B page 29 PICDEM 17 Demonstration Board User s Guide Branch to prolog moviw HIGH TOCKI prolog movwf PCLATH moviw LOW TOCKI prolog movwf PCL po k k k k k kc RRE AREA ke ke e ke ke ke e K ke ke K he ke ke he ke A K he ke A K he ke kc he ke ke K he ke ke che he ke e e he e e _PIV sec CODE H 4020 Save ALUSTA movpf ALUSTA save ALUSTA must save ALUSTA before others movpf WREG Save WREG temporarily save off WREG Branch to prolog moviw HIGH PIV prolog movwf PCLATH moviw LOW PIV prolog movwf PCL po k k kk k ec K ke ke ce ke A K ke ke e K ke ke K he ke ke he ke K K he ke ce he ke ke K he ke ehe he ke ee he ke e LELE InterruptCode CODE INT prolog Save BSR and WREG movfp BSR PCLATH clrf BSR 1 movpf PCLATH save BSR Service the interrupt by calling the interrupt handling function goto INT 2 INT 1 BANKSEL fpINT movfp fpINT 1 PCLATH movfp fpINT PCL _INT 2 call _INT_1 push address of next instruction on stack Restore WREG and BSR clrf BSR 1 BSR was saved in bank 0 movfp save BSR BSR Now restore it movfp save WREG WREG and WREG as well Restore PCLATH and ALUSTA movfp save PCLATH PCLATH movfp save ALUSTA ALUSTA Return from interrupt
27. the define UPPER define UPPER DATA PORT defines the port on which the LCD data lines are connected to define DATA PORT PORTF define TRIS DATA PORT DDRF CTRL PORT defines the port where the control lines are connected These are just samples change to match your application define RW PIN PORTGbits RGO Port for RW define TRIS RW DDRGbits RGO TRIS for RW 2001 Microchip Technology Inc DS39024B page 39 PICDEM 17 Demonstration Board User s Guide define RS PIN PORTFbits RF7 Port for RS define TRIS_RS DDRFbits RF7 TRIS for RS define E PIN PORTGbits RG1 PORT for E define TRIS_E DDRGbits RG1 TRIS for E Display ON OFF Control defines define DON 0b00001111 Display on define DOFF 0b00001011 Display off define CURSOR_ON 0b00001111 Cursor on define CURSOR_OFF 0b00001101 Cursor off define BLINK_ON 0b00001111 Cursor Blink define BLINK_OFF 0b00001110 Cursor No Blink Cursor or Display Shift defines define SHIFT CUR LEFT 0b00010011 Cursor shifts to the left define SHIFT CUR RIGHT 0b00010111 Cursor shifts to the right define SHIFT DISP LEFT 0b00011011 Display shifts to the left define SHIFT DISP RIGHT 0b00011111 Display shifts to the right Function Set defines define FOUR_BIT 0b00101111 4 bit Interface define EIGHT BIT 0b00111111 8 bit Interface define LINE 5X7 0b00110011 5x7 characters single line
28. 000 ESA 67 D2 8 B ee P2 00000 00000 PI D3 o o 0000 e e 0000 o es USART2 USART1 I o s Monitor l eeeeeeee Figure A 1 PICDEM 17 Demonstration Board Parts Layout 2001 Microchip Technology Inc DS39024B page 75 PICDEM 17 Demonstration Board User s Guide A 1 SCHEMATIC 1 C20 sv Hd Q 1uF aca RD7 Cena Res Ros ca a cs r03 Rce Ro2 c7 al of ri of o na 2 amp e 2 3 4 3 3 se ee2e28282482 828 228 Ge 19 Joo RAQ SO ei Se L ene real bes 12 REO rait 58 Se ex Dier R83 37 f ez 14 rez U1 RB4 38 fx 15 lez 17C756TH past 55 gg Ga 16 GR RB2 mm 17 Leer vss 53 NC nc 2 Ae osca 5V hno osc 52 mM vop 8 5V Gal e NP es NETT S rag 42 Rm _ C14 9 1uF 46 iE sn RA3 us 0 1uF y 25 Jers Raz fraz a ashe Rar pt e 822292328229823225221 zl lt ur dc ac KE Z c E E E mE taasyaqaga az 4 dan gas dy 2 el EI ral Ras AVDD ee er C12 Q 1uF E t sv 2 Jets 0 1uF DS39024B page 76 O 2001 Microchip Technology Inc PICDEM 17 Demonstration Board Schematics A 2 SCHEMATIC 2 C21 5v Fi K Q1uF Re 07 fca Res fica DD m
29. 3 to convert between RS 232 voltage levels and CMOS TTL voltage levels Both USART1 and USART2 I O pins are routed to this device as well as the I O pins used for hardware handshaking The DB9 connector P1 is used for USART1 and P2 is used for USART2 The Monitor program running on the PICDEM 17 demonstration board uses USART2 for the communications channel between the PICDEM 17 demonstration board and the Host PC 3 7 CAN Bus Interface The PICDEM 17 demonstration board has the layout for the Microchip MCP2510 CAN Bus peripheral and the PCA82C250 CAN Bus interface These devices must be provided by the user To use the CAN Bus interface the user must do the following in addition to adding the components to the board Use a canned oscillator in O2 and remove the oscillator from O1 Set the DIP switch S13 for SPI SDA amp SCL OFF SCK SDO SDI amp CS ON Set the DIP switch S14 for CAN Bus SDA amp SCL OFF CANH amp CANL ON DEEN DS39024B page 20 2001 Microchip Technology Inc Hardware Description 3 8 Modular Connectors As described previously the modular connectors can be used to set up a CAN Bus or a 1 C Bus by simply connecting standard 4 or 6 conductor phone cable Refer to Figure A 1 in Appendix A for the pinout of the connectors 2001 Microchip Technology Inc DS39024B page 21 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 22 2001 Microchip Technology Inc PICDEM
30. 42 Tel 937 291 1654 Fax 937 291 9175 Detroit Tri Atria Office Building 32255 Northwestern Highway Suite 190 Farmington Hills MI 48334 Tel 248 538 2250 Fax 248 538 2260 Los Angeles 18201 Von Karman Suite 1090 Irvine CA 92612 Tel 949 263 1888 Fax 949 263 1338 Mountain View Analog Product Sales 1300 Terra Bella Avenue Mountain View CA 94043 1836 Tel 650 968 9241 Fax 650 967 1590 New York 150 Motor Parkway Suite 202 Hauppauge NY 11788 Tel 631 273 5305 Fax 631 273 5335 San Jose Microchip Technology Inc 2107 North First Street Suite 590 San Jose CA 95131 Tel 408 436 7950 Fax 408 436 7955 Toronto 6285 Northam Drive Suite 108 Mississauga Ontario L4V 1X5 Canada Tel 905 673 0699 Fax 905 673 6509 ASIA PACIFIC China Beijing Microchip Technology Beijing Office Unit 915 New China Hong Kong Manhattan Bldg No 6 Chaoyangmen Beidajie Beijing 100027 No China Tel 86 10 85282100 Fax 86 10 85282104 China Shanghai Microchip Technology Shanghai Office Room 701 Bldg B Far East International Plaza No 317 Xian Xia Road Shanghai 200051 Tel 86 21 6275 5700 Fax 86 21 6275 5060 Hong Kong Microchip Asia Pacific RM 2101 Tower 2 Metroplaza 223 Hing Fong Road Kwai Fong N T Hong Kong Tel 852 2401 1200 Fax 852 2401 3431 India Microchip Technology Inc India Liaison Office Divyasree Chambers 1 Floor Wing A A3 A4 No 11 O Shaugnessey Road Bangalore 560 025 I
31. A 2 From the Program Manager Run option type A SETUP The PICDEM 17 Monitor Setup program displays a Welcome message box with options to continue or exit Click OK to continue 3 Setup next displays a dialog to select the directory to install the execut able and source code files If directory other than the default is desired enter the name and click OK 4 After copying the PICDEM 17 Monitor files Setup displays a message box with the caption The PICDEM 17 Monitor installation has completed Click OK 2001 Microchip Technology Inc DS39024B page 7 PICDEM 17 Demonstration Board User s Guide 2 4 Using the PICDEM 17 Monitor Program The Monitor program uses a Serial port on the Host PC It currently supports COM through COMA The command line to execute the Monitor program should be 756MON EXE COM where is the desired COM port 1 2 3 or 4 The PICDEM 17 Monitor program should look like Figure 2 1 PICDEM 17 Monitor v1 00 Jx Source file C Program memory Read Messages v1 01 00 Figure 2 1 PICDEM 17 Monitor Program Once the Monitor program has been started connect the serial cable to P2 on the PICDEM 17 demonstration board Then apply power to the PICDEM 17 demonstration board The PICDEM 17 demonstration board should display the following message in the message window on the Monitor Program Boot Mon V2 2 22 2 D where is the version of the Monitor firmwa
32. CROCHIP BOARD USER S GUIDE Chapter 1 About PICDEM 17 Demonstration Board 1 1 Introduction This chapter describes the features of the PICDEM 17 demonstration board 1 2 Highlights This chapter covers the following topics Processor Sockets External FLASH Memory Memory Mapping Power Supply Prototyping Areas Oscillator Options RS 232 Serial Ports Push button Switches LEDs Analog Circuitry External LCD Interface CAN Bus Interface 24LC01B Serial EEPROM Modular Connectors Pre programmed Sample Note All following part references can be found in Figure A 1 1 in Appendix A PICDEM 17 Demonstration Board Schematics For example the 68 pin PLCC socket for the PIC17C75X microcontrol lers is located at U1 on the Parts Layout 1 3 Processor Sockets The PICDEM 17 demonstration board supports the following devices 68 pin PLCC socket for the PIC17C75X microcontrollers U1 84 pin PLCC socket for the PIC17C76X microcontrollers U7 2001 Microchip Technology Inc DS39024B page 3 PICDEM 17 Demonstration Board User s Guide 1 4 External FLASH Memory The PICDEM 17 demonstration board supports all operating modes of the PIC17C7XX PICmicro microcontroller However the Monitor program uses the extended microcontroller mode of operation The FLASH is the AM29F100T device from AMD configured as 64K x 16 The monitor program supports downloading code into the FLASH and then running the program
33. DEM 17 demonstration board Any additional digits are ignored The firmware in the PIC17C756A ignores any write program memory commands with an address in the range of 0000h to 3FFFh 2001 Microchip Technology Inc DS39024B page 17 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 18 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 3 Hardware Description 3 4 Introduction The hardware on the PICDEM 17 demonstration board is simple and is intended to illustrate the ease of use and capabilities of the PIC17C7XX family of devices 3 2 Highlights This chapter covers the following topics Port Connections e Push button Switches DIP Switches e RS 232 Interface CAN Bus Interface e Modular Connectors 3 3 Port Connections The following bullets list the I O features and port connections for the PIC17C7XX devices PORTA 0 1 not used PORTA lt 2 3 gt used for SPI 12C interface PORTA lt 4 5 gt used for USART1 interface PORTB lt 0 3 gt not used PORTB lt 4 5 gt used for USART2 handshaking interface CTS RTS PORTB lt 6 7 gt used for SPI IC interface All of PORTC and PORTD are dedicated to the external memory inter face PORTE lt 0 2 gt are used in the external memory interface as ALE OE and WR respectively PORTF lt 0 3 gt are used as the data lines for the external LCD PORTF lt 4 6 gt not used PORTF lt 7 gt used as th
34. E 23 42 LL Lu sostiene tnm 23 4 3 Linker Senprrile eee e o DDR MILL ERA EE tes 24 4 4 Startup Code File uae ote late edi s aloe 26 4 5 Jrit rrupr Gode EE 28 4 5 WEE BIIBS c taies oo ab dai 33 LCD C Description Sch INTOdACHON sd aoo matado Da 35 5 2 MPLAB IDE Project Files tege dee aca 35 53 Pl micio O bres cetonas AD A tl dal e ae 36 54 Source Code Descriptions annee iia 36 5 5 UCD Source Code Listing oo ea 37 5 6 XLCD H Source Code Listing e e e 39 5 7 XLCD C Source Code Listing EE 42 USART C Description A o Ee 57 DS39024B page 4 2001 Microchip Technology Inc Table of Contents 6 2 6 3 6 4 6 5 6 6 Chapter 7 7 1 7 2 7 3 7 4 Chapter 8 8 1 8 2 8 3 8 4 8 5 8 6 Chapter 9 9 1 9 2 9 3 9 4 9 5 9 6 elen 57 MPLAB IDE Project EE 57 AA A 58 Source Code Descriptions nn 58 USART C Source Code Listing unseren poter neas 59 ANALOG C Description inier WEE 61 Plet 62 Source Code Descriptions i 62 ANALOG C Source Code Listing EE 63 SWITCH C Description ageet 110 rtc 65 elen 65 MPLAB IDE Project Biles vas ii 65 PIGIBICEO EIDEGPIBS aio CAL in ta ected ote eege 66 Source Code Descriptions Au 66 SWITCH C Source Code SI tee ete ha eoe un as 67 I2C C Description is a O EN 69 elle lien 69 MPLAB IDE Project Files cereo erret teen 69 PIGmicro G ee 70 Source Code Descriptions eee nn
35. EM 17 demonstration board provides two prototyping areas one for analog and one for digital The PICDEM 17 demonstration board was designed to fully demonstrate the capabilities of the on chip A D converter In addition to the separate analog power supply and voltage reference the printed circuit board has four layers with two signal layers and a power and ground layer The analog prototyping area has all A D channels analog VDD and Vss as well as the voltage reference available to the user The digital prototyping area has all other I O pins complete 16 bit address bus digital VDD and Vss and additional memory mapped peripheral signals DS39024B page 4 2001 Microchip Technology Inc About PICDEM 17 Demonstration Board 1 8 Oscillator Options The PICDEM 17 demonstration board layout will only accept a canned oscillator The use of a crystal or ceramic resonator requires that the user modify the board 1 9 RS 232 Serial Ports The PICDEM 17 demonstration board supports both USARTs on the PIC17C7XX devices A level shifting IC is used to convert from the TTL CMOS levels out of the PIC17C7XX to the RS 232 voltages USART2 also has the capability to function in a hardware handshaking mode using RTS and CTS These signals are level shifted and connected to PORTB pins 4 CTS and 5 RTS 1 10 Push button Switches The PICDEM 17 demonstration board has 8 general purpose push button switches that are available to the user These
36. Function Name put sXLCD Return Value void Parameters buffer pointer to string Description This routine writes a string of bytes to the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine The data is written to the character generator RAM or the display data RAM depending on what the previous SetxxRamAddr routine was called KKAKKAKKAKAAKAAAAAAAAAAKAAAKAAKAKAKAKAKAKAKKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKk void putsXLCD static char buffer DS39024B page 42 O 2001 Microchip Technology Inc LCD C Description while buffer Write data to LCD up to null while BusyXLCD Wait while LCD is busy WriteDataXLCD buffer Write character to LCD buffer Increment buffer return EEEIEE NEE OA VAE EO VE OLE TEOR IE PRO Function Name putrsXLCD Return Value void Parameters buffer pointer to string Description This routine writes a string of bytes to the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine The data is written to the character generator RAM or the display data RAM depending on what the previous SetxxRamAddr routine was called KKAKAKKAKAKAKAKAKAAKAKAAAAKAAKAAAKAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk void putrsXLCD static const rom char buffer while buff
37. G RES 1 ALUSTA RES Si CPUSTA Bank 2 INTSAVE SEC2 UDATA SAVEINT START 0x201 RES 1 WREG DS39024B page 28 2001 Microchip Technology Inc Using the MPLAB C17 C Compiler RES 1 ALUSTA RES 1 CPUSTA Bank 3 INTSAVE SEC3 UDATA SAVEINT START 0x301 RES WREG RES ALUSTA RES 1 CPUSTA po k k kk k kk ke ke ke ke ke ke ke e e ke ke e K ke ke e he ke ke K he ke K K he ke kc he ke ec he ke e che he ke khe he ke e e he RR VARIABLES UDATA OVR These are the function pointers that have the i s r addresses fpINT RES fpTMRO RES fpTOCKI RES fpPIV RES N NNN GLOBAL fpINT fpTMRO fpTOCKI fpPIV po k k RRR KERR ke ke KKK ERR e K ke ke e K ke ke RK RE RRA ke ce he KERR he ke che he ke e ce he ERR he ke e RR INT sec CODE H 4008 Save ALUSTA movpf ALUSTA save ALUSTA must save ALUSTA before others movpf WREG Save WREG temporarily save off WREG Branch to prolog moviw HIGH INT prolog movwf PCLATH movlw LOW INT prolog movwf PCL po k kk k k k k k k K k K he ke e k he ke e he he ke K he KERR he ke RRR KERR RAR KEKE KERR ke ehe he ke e e he e e TMRO sec CODE H 4010 Save ALUSTA movpf ALUSTA save ALUSTA must save ALUSTA before others movpf WREG Save WREG temporarily save off WREG Branch to prolog moviw HIGH TMRO prolog movwf PCLATH movlw LOW TMRO prolog movwf PCL po k k kk LE RRE AER he ke ke e K ke ke K ke ke K he ke ke K he ke kc he ke echo ke e
38. KKKKAKk unsigned char ReadAddrXLCD void char data Holds the data retrieved from the LCD ifdef BIT8 8 bit interface RW_PIN 1 Set control bits for the read RS_PIN 0 DelayFor18TCY E PIN 1 Clock data out of the LCD controller DelayFor18TCY data DATA PORT Save the data in the reg ister E PIN 0 RW PIN 0 Reset the control bits else 4 bit interface RW_PIN 1 Set control bits for the read RS_PIN 0 DelayForl8TCY E PIN 1 Clock data out of the LCD controller DelayForl8TCY ifdef UPPER Upper nibble interface data DATA PORT amp 0xf0 Read the nibble into the upper nibble of data else Lower nibble interface data DATA PORT lt lt 4 amp 0x 0 Read nibble to upper nibble of data endif E PIN 0 Reset the clock DelayFor18TCY E PIN 1 Clock out the lower nib ble DelayFor18TCY Hifdef UPPER Upper nibble interface data DATA PORT gt gt 4 amp 0x0f Read nibble to lower nibble of data Helse Lower nibble interface data DATA PORT amp 0x0f Read nibble to lower nib ble of data endif E PIN 0 RW_PIN 0 Reset the control lines Hendif return data amp 0x7E Return the address Mask off the busy bit DS39024B page 52 2001 Microchip Technology Inc LCD C Description SEN Function Name ReadDataXLCD Return Value char data byte from LCD control
39. KKKKKKKKKKKKKKKKKKk void SetCGRamAddr static unsigned char CGaddr while BusyXLCD ifdef BIT8 8 bit interface TRIS DATA PORT 0 Make data port ouput DATA PORT CGaddr 0501000000 Write cmd and address to port RW PIN 0 Set control sig nals RS PIN 0 DelayForl8TCY E PIN 1 Clock cmd and address in DelayForl8TCY E PIN 0 DelayForl8TCY TRIS DATA PORT Oxff Make data port inputs else 4 bit interface ifdef UPPER Upper nibble interface TRIS DATA PORT amp OxO0f Make nibble input DATA PORT amp Ox0f and write upper nibble DATA PORT CGaddr 0501000000 amp Oxf0 else Lower nibble interface TRIS DATA PORT amp 0xf0 Make nibble input DATA PORT amp Oxf0 and write upper nibble DATA PORT CGaddr 0b01000000 gt gt 4 amp Ox0f endif RW_PIN 0 Set control sig nals RS_PIN 0 DelayForl8TCY E PIN 1 Clock cmd and address in DelayForl8TCY E PIN 0 ifdef UPPER Upper nibble interface DATA PORT amp Ox0f Write lower nib ble DATA PORT CGaddr lt lt 4 amp 0xf0 DS39024B page 48 2001 Microchip Technology Inc LCD C Description else Lower nibble interface DATA PORT amp Oxf0 Write lower nib ble DATA PORT CGaddr amp 0x0f endif DelayForl8TCY E PIN 1 Clock cmd and address in DelayForl8TCY E PIN 0 Hifdef UPPER Upper nib
40. ME SFRShareA START 0x500 END 0x50F HAREBANK PROTECTE NAME SFRShareA START 0x600 END 0x60F HAREBANK PROTECTE NAME SFRShareA START 0x700 END 0x70F 2 SFRs in banks 0 7 DATABANK PROTECTED NAME SFRO START 0x010 END 0x017 DATABANK PROTECTED NAME SFR1 START 0x110 END 0x117 DATABANK PROTECTED NAME SFR2 START 0x210 END 0x217 DATABANK PROTECTED NAME SFR3 START 0x310 END 0x317 DS39024B page 24 2001 Microchip Technology Inc Using the MPLAB C17 C Compiler DATABANK PROTECTED NAME SFR4 START 0x410 END 0x417 DATABANK PROTECTED NAME SFR5 START 0x510 END 0x517 DATABANK PROTECTED NAME SFR6 START 0x610 END 0x617 DATABANK PROTECTED NAME SSR7 START 0x710 END 0x717 3 SFRs shared 0x18 to 0x19 SHAREBANK PROTECTED NAME SFRShareB START 0x018 END 0x019 General Purpose Data Memory 1 GPRs that are shared 0x1A to 0x1F SHAREBANK NAME GPRShare START 0x01A END 0x01F 2 GPRs in banks 0 1 DATABANK NAME GPRO START 0x020 END 0x0FF DATABANK NAME GPR1 START 0x120 END 0x1FF DATABANK NAME GPR2 START 0x220 END 0x2FF DATABANK NAME GPR3 START 0x320 END 0x3FF Declare a stack STACK SIZE 0x20 2001 Microchip Technology Inc DS39024B page 25 PICDEM 17 Demonstration Board User s Guide 4 4 Startup Code File The startup code file is used to call the startup function if enabled initialize data routine if enabled initialize the stack and then branch to the mai
41. OR TR TR TR TR RARA RRA k k k RRA RRA 2 December 1998 Compiled using MPLAB C17 C Compiler V2 20 J BRR RR RR RR RR RR RR RRA RR RR RR RRA k k RRA RAR This program toggles the state of the memory mapped LEDs when the corresponding memory mapped EJE switch is pressed J BRR RR RK ok kok KO RR E RR RR RR RRA Re Uses an oscillator of 16MHz S RRR RRR k k k k k KR k KKK k k RR KKK k k k KR KKK HR k k KR k k k k k k k k KK include lt p17c756 h gt include lt delays h gt void main void unsigned int LEDbuf unsigned int SWTbuf unsigned int TEMPbuf unsigned int Temp rom int LEDptr rom int SWTptr Initialize pointers to the memory mapped device LEDptr rom int Oxfffd SWTptr rom int Oxfffc Initialize the LEDs and other variables LEDptr Ox00ff LEDbuf Ox00ff SWTbuf Ox00ff while 1 Read the state of the switches TEMPbuf SWTptr amp OxOOff Determine what switch states have changed Temp TEMPbuf SWTbuf If a switch state has changed and the change was a switch press if Temp amp amp TEMPbuf OxOOff If need to toggle LED low if Temp amp LEDbuf Mask off desired LED LEDbuf amp Temp Else need to toggle LED high 2001 Microchip Technology Inc DS39024B page 67 PICDEM 17 Demonstration Board User s Guide else OR in desired LED LEDbuf Temp Write new value to LEDs LEDptr LEDbuf
42. PIC17C756A sample is included with the PICDEM 17 demonstration board It has been programmed with the Monitor firmware to communicate with the Monitor program on the PC This device should be used with the 16 MHz canned oscillator in the socket labeled O1 DS39024B page 6 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 2 Using the PICDEM 17 Monitor 2 1 Introduction This chapter discusses how to use the Monitor program to interact with the PIC17C7XX device on the PICDEM 17 demonstration board 2 2 Highlights This chapter includes Installing the PICDEM 17 Monitor Program Running the PICDEM 17 Monitor Program Resetting the PICDEM 17 Demonstration Board Erasing the FLASH on the PICDEM 17 Demonstration Board Downloading HEX Files to PICDEM 17 Demonstration Board Running HEX Files from the PICDEM 17 Demonstration Board Running Diagnostics on the PICDEM 17 Demonstration Board Modifying Memory Contents 2 3 Installing the PICDEM 17 Monitor Program The PICDEM 17 Monitor program setup routine installs the monitor program PC monitor source code and the PIC17C756A monitor source code into the MPLAB IDE directory Microsoft Windows 95 must be running to execute the Monitor Setup program The files can be installed under the default MPLAB IDE directory C Program Files MPLAB 756MON or in another directory 1 Insert the PICDEM 17 Monitor installation disk in drive
43. PICDEM 17 DEMONSTRATION BOARD USER S GUIDE All rights reserved Copyright 2001 Microchip Technology Incorporated USA Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates No rep resentation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accu racy or use of such information or infringement of patents or other intellectual property rights arising from such use or oth erwise Use of Microchip s products as critical components in life support systems is not authorized except with express written approval by Microchip No licenses are conveyed implicitly or otherwise under any intellectual property rights The Microchip logo and name are registered trademarks of Microchip Technology Inc in the U S A and other countries All rights reserved All other trademarks mentioned herein are the property of their respective companies No licenses are conveyed implicitly or otherwise under any intellectual prop erty rights DNV Certification Inc DNV MSC USA The Netherlands Accredited by the RvA ANSI RAB ES DNY ISO 9001 QS 9000 REGISTERED FIRM QMS k M nN Trademarks The Microchip name logo PIC PICmicro PICMASTER PIC START PRO MATE KEELOQ SEEVAL MPLAB and The Embedded Control Solutions Company are registered trade marks of Microchip Technol
44. PLAB ICE in circuit emulator are deferred to the individual product data sheets and user s manuals respectively Chapter 1 Introduction This chapter introduces the PICDEM 17 demonstration board and provides a brief description of the hardware Chapter 2 Using the PICDEM 17 Monitor This chapter discusses how to use the PICDEM 17 Monitor PC program and the pre programmed PIC17C756A device Chapter 3 Hardware Description This chapter describes in detail the hardware of the PICDEM 17 demonstration board Chapter 4 Using MPLAB C17 C compiler with PICDEM 17 demonstration board This chapter provides a description of how to write and compile code for execution on the PICDEM 17 demonstration board Some special files are required for use with the MPLAB C17 C compiler to correctly compile programs to run in the external FLASH program memory Chapter 5 LCD c Description This chapter provides a detailed description of the demonstration program for the PIC17C756A that interfaces to an external LCD panel using an Hitachi HD44780 display controller or equivalent Chapter 6 USART C Description This chapter provides a detailed description of the demonstration program for the PIC17C756A that displays data to the USART Chapter 7 ANALOG C Description This chapter provides a detailed description of the demonstration program for the PIC17C756A that reads an A D channel and displays the results in the Monitor program window
45. R TR TOR TOR RRA Uses an oscillator of 16MHz J BRR RRR RR kok RAR RR RR RRA RRA RAR RR RARA RRA k k k RRA RRA include lt p17c756 h gt include lt delays h gt include i2c16 h include lt usart16 h gt include lt stdlib h gt void PutsUSART2 char data void PutcUSART2 char data Prints a string to USART2 using hardware handshaking void PutsUSART2 char data do Wait for USART2 to finish prev operation while BusyUSART2 Wait for CTS while PORTBbits RB4 Write a character to USART2 putcUSART2 data while data Increment pointer and check for NULL return Prints a character to USART2 using hardware handshaking void PutcUSART2 char data while BusyUSART2 Wait for USART2 to finish while PORTBbits RB4 Wait for CTS 2001 Microchip Technology Inc DS39024B page 71 PICDEM 17 Demonstration Board User s Guide putcUSART2 data Print charac ter to USART2 return void main void rom int LEDptr unsigned char addr unsigned char byte char str 5 char crlf 3 Initialize the carriage return linefeed string crlf 0 0x0d crlf 1 0x0a crlt 2 0 Initialize the pointer to LEDs LEDptr rom int Oxfffd Initialize the I2C module OpenI2C MASTER SLEW_ON SSPADD 9 Initialize USART2 and hardware handshaking PORTBbits RB5 1 DDRBbits RB5 0 OpenUSART2 USART TX IN
46. RK k k k KKK include lt p17c756 h gt include lt delays h gt include xlcd h Constant string arrays in program memory const rom char Hello Hello const rom char World World Delays for 18 Tcy void DelayFor18TCY void Delayl0TCY Delayl0TCY return Delays for 15ms void DelayPORXLCD void DelaylKTCYx 70 return Delays for 5ms void DelayXLCD void Delay1KTCYx 20 return void main void Turn A D off ADCON1 0x0e Configure the external LCD OpenXLCD FOUR BIT amp LINES 5X7 y _ _ ___ _ _ ___ S PE_ABOMN O 2001 Microchip Technology Inc DS39024B page 37 PICDEM 17 Demonstration Board User s Guide Print the Hello message to the first line putrsXLCD Hello Wait for the LCD to finish last command while BusyXLCD Set the cursor to the start of the 2nd line SetDDRamAddr 0x28 Print the World message to the 2nd line putrsXLCD World Endless loop to end program while 1 Nop Nop MAN DS39024B page 38 2001 Microchip Technology Inc LCD C Description 5 6 XLCD H Source Code Listing pragma nolist BRR ok kok ok kok RIO IR RER TR TR TR TOR TR TOR TOR TOR RIOR kok e ke ee PICmicro C Libraries V2 10 Written and Tested using MPLABC V2 10 KKAKKAKKAKAKAKAAKAAAAKAAAAAKAAKAKAKAKAKAKAKAKKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
47. RT amp Oxf0 and write upper nibble DATA PORT DDaddr 0b10000000 gt gt 4 amp Ox0f endif RW_PIN 0 Set control bits RS_PIN 0 DelayForl8TCY E PIN 1 Clock the cmd and address in DelayForl8TCY E PIN 0 ifdef UPPER Upper nibble interface DATA PORT amp 0x0 Write lower nib ble DATA PORT DDaddr lt lt 4 amp 0xf0 else Lower nibble interface DATA PORT amp Oxf0 Write lower nib ble DATA PORT DDaddr amp 0x0f endif DelayForl8TCY E PIN 1 Clock the cmd and address in DelayForl8TCY E PIN 0 Hifdef UPPER Upper nibble interface TRIS DATA PORT 0xf0 Make port input Helse Lower nibble interface TRIS DATA PORT Ox0f Make port input Hendif Hendif return ian Function Name BusyXLCD Return Value char busy status of LCD controller Parameters void Description This routine reads the busy status of the Hitachi HD44780 LCD controller KKAKKAKAKAAKAAKAAAAAAAAAAKAAKAKAKAKAKAKAKAKKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk unsigned char BusyXLCD void RW_PIN 1 Set the control bits for read RS PIN 0 DelayFor18TCY E PIN 1 Clock in the com mand DS39024B page 50 O 2001 Microchip Technology Inc LCD C Description DelayFor18TCY Hifdef BITS 8 bit interface if DATA PORT 7 Read bit 7 busy bit 1f high E PIN 0 Reset cl
48. Source Code Listing 8 3 MPLAB IDE Project Files The project SWITCH PJT contains the following files SWITCH PJT DEMO756L LKR I P17C756 0 PMC756L LIB COL17DEM O SWITCH C The files in this project use the following header files P17C756 H DELAYS H 2001 Microchip Technology Inc DS39024B page 65 PICDEM 17 Demonstration Board User s Guide 8 4 PlCmicro C Libraries The files in SWITCH PJT use the following library function s contained in PMC756L LIB Delay1KTCYx 8 5 Source Code Descriptions DEMO756L LKR This file is the linker script file for the project P17C756 0 linker script file PMC756L LIB This file contains the library functions compiled for large memory model it is included by the linker script file COL17DEM O This file contains the startup code to initialize the stack initialize data call the startup function and jump to main SWITCH C This file is the main source code file for the project P17C756 H This header file contains processor specific items DELAYS H This is the header file for delay routines in the library Z W a DS39024B page 66 2001 Microchip Technology Inc SWITCH C Description 8 6 SWITCH c Source Code Listing J BRR RR ok kok ok kok ok IR kok ok TR TR TR TR He SWITCH C AAA Rodger Richey Principal Applications Engineer Microchip Technology Incorporated LL BRR RR ok kok ok kok KO IR T
49. T C Source Code Listing LL BRR RR RR RR RR RR RR RR RR RR RR RR RR RRA RR RRA USART C BRR RRR RO kok ok RR RR oko E kc ko kk oko TOR doo k k K RARE Rodger Richey Principal Applications Engineer Microchip Technology Incorporated LL BRR RK ok kok KK TR TOR TR TR TR TR TOR TOR Re 2 December 1998 Compiled using MPLAB C17 C Compiler V2 20 J BRR RRR RR RR RAR RR RR RR RR RRA RR RRA RRA k k k RR RRA This program prints an incrementing count from 0 to 255 to the USART The numbers are displayed in the Monitor program J BRR RR e e e IK ok kok ok oko ok TR TR TR TR TOR He Uses an oscillator of 16MHz J RRR RRR k k k k k k KR k KR KK k k k KR KKK k k k k KKK k k k k KKK k k k RK KKK k k LE KK include lt p17c756 h gt include lt delays h gt include lt usart16 h gt include lt stdlib h gt void PutsUSART2 char data Function to print a string to USART2 using handshaking void PutsUSART2 char data do Wait for USART to complete prev operation while BusyUSART2 Hardware handshaking for CTS while PORTBbits RB4 Print a character to USART2 put cUSART2 data while data Increment pointer and check for NULL return void main void unsigned char i char str 5 char crlf 3 Initialize the carriage return linefeed string crlf 0 0x0d crlf 1 0x0a crlf 2 0 Initialize USART2 and the hardw
50. T OFF amp USART RX INT OFF amp USART ASYNCH MODE amp USART EIGHT BIT amp USART CONT RX 25 Print a carriage return and linefeed PutsUSART2 crlf Initialize address to 0 addr 0 while 1 LEDptr addr Write address to LEDS Write a byte to the EEPROM EEByteWrite 0xa0 addr addr Wait for the EEPROM EEAckPolling 0xa0 Read a byte from the EEPROM byte EERandomRead 0xa0 addr ubtoa addr str Convert address to ASCII PutsUSART2 str Print the string to USART2 PutcUSART2 Print a space to USART2 ubtoa byte str Convert the byte to ASCII PutsUSART2 str Print the string to USART2 DS39024B page 72 2001 Microchip Technology Inc I c c Description to USART2 address Put sUSART2 crlf addr if addr gt 127 addr 0 Delay10KTCYx 250 Print a CRLF Increment the 1f gt 127 reset to 0 Wait a while 2001 Microchip Technology Inc DS39024B page 73 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 74 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Appendix A PICDEM 17 Demonstration Board Schematics
51. USART PJT contains the following files USART PJT DEMO756L LKR r P17C756 0 L PMC756L LIB COL17DEM O USART C The files in this project use the following header files P17C756 H DELAYS H USART16 H STDLIB H 2001 Microchip Technology Inc DS39024B page 57 PICDEM 17 Demonstration Board User s Guide 6 4 PICmicro C Libraries The files in USART PJT use the following library function s contained PMC756L LIB DelaylOKTCYx BusyUSART2 putcUSART2 OpenUSART2 ubtoa C 6 5 Source Code Descriptions DEMO756L LKR P17C756 0 PMC756L LIB COL17DEM O USART C P17C756 H DELAYS H USART16 H STDLIB H This file is the linker script file for the project This file contains the processor dependent objects it is included by the linker script file This file contains the library functions compiled for large memory model it is included by the linker script file This file contains the startup code to initialize the stack initialize data call the startup function and jump to main This file is the main source code file for the project This header file contains processor specific items This is the header file for delay routines in the library This is the header file for the USART routines in the library This is the header file for standard library routines DS39024B page 58 2001 Microchip Technology Inc USART C Description 6 6 USAR
52. acta scene aa NA nee 4 1 6 Oscillator EI le TEE 5 1 9 RS 232 Serial Ports EE 5 1 10 Push button Switches i 5 Hd D D E 5 1 12 Analog Circuitry EE 5 1 13 External LCD Interface aaa 5 1 14 CAN Bus Interface one ie ii i 6 1 15 24L CO TB Serial EEPROM ze indi iaa 6 1416 Modular CONNECIORS tm 6 1 17 Pre programimed Sample ari ai datasets 6 Chapter 2 Using the PICDEM 17 Monitor 2 DIEU tee 7 EEN ele ele EE 7 2 3 Installing the PICDEM 17 Monitor Program ee 7 2 4 Using the PICDEM 17 Monitor Program eee 8 2 5 Resetting the PICDEM 17 Demonstration Board 9 2 6 Erasing the FLASH on the PICDEM 17 Demonstration Board 9 2001 Microchip Technology Inc DS39024B page 3 PICDEM 17 Demonstration Board User s Guide Chapter 3 Chapter 4 Chapter 5 Chapter 6 2 7 Downloading HEX Files to the PICDEM 17 Demonstration Board 9 2 8 Running HEX files from the PICDEM 17 Demonstration Board 10 2 9 Running Diagnostics on the PICDEM 17 Demonstration Board 11 2 10 Modifying Memory Contents_ 14 Hardware Description Sch ITO CE CHOTU o alu e E nite auus ta ui 19 ae Te ale 19 9 9 Pon Conneclions EE 19 3 4 Push button Switches eee eee eee eee eee eee een 20 mo LDIPASWIeles uz top EE a 20 3 60 RASs232 ue 20 3 7 CAN Bus Interface EE 20 3 8 Modular Connectors ee 21 Using the MPLAB C17 C Compiler 4 1 Introduction M
53. are handshaking lines PORTBbits RB5 1 DDRBbits RB5 0 2001 Microchip Technology Inc DS39024B page 59 PICDEM 17 Demonstration Board User s Guide OpenUSART2 USART TX INT OFF amp USART RX INT OFF amp USART ASYNCH MODE amp USART EIGHT BIT amp USART CONT RX 25 Send a carriage return and linefeed PutsUSART2 crlf Initialize the count variable i 0 while 1 Convert the count variable to ASCII ubtoa i str Print the string PutsUSART2 str Print a carriage return and linefeed PutsUSART2 crlf Wait for a while Delay10KTCYx 250 Delay10KTCYx 250 Increment the count variable i DS39024B page 60 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 7 ANALOG C Description T 1 Introduction This chapter describes the demonstration program for the PIC17C756A ANALOG C This program continuously converts on channel 0 which is connected to a precision 4 096V voltage reference and displays the result in ASCII on the Monitor program The A D module is configured to use the AVDD and AVSS pins as the voltage reference Highlights This chapter covers the following topics MPLAB IDE Project Files PICmicro C Libraries Source Code Descriptions ANALOG C Source Code Listing MPLAB IDE Project Files The project ANALOG PJT contains the following files ANALOG PUT DEMO756L LKR m P17C756 0
54. ble interface TRIS DATA PORT 0xf0 Make inputs Helse Lower nibble interface TRIS DATA PORT 0x0f Make inputs endif Hendif return kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk Function Name SetDDRamAddr Return Value void Parameters CGaddr display data address Description This routine sets the display data address of the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine KKAKAKKAKAKAKAAAAAAAAAAAAAAKAKAKAKAKAKKAKKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAK void SetDDRamAddr static unsigned char DDaddr while BusyXLCD ifdef BIT8 8 bit interface TRIS DATA PORT 0 Make port output DATA PORT DDaddr 0510000000 Write cmd and address to port RW PIN 0 Set the control bits RS PIN 0 DelayFor18TCY E PIN 1 Clock the cmd and address in DelayForl8TCY E PIN 0 DelayForl8TCY TRIS DATA PORT Oxff Make port input else 4 bit interface ifdef UPPER Upper nibble interface TRIS DATA PORT amp OxO0f Make port output DATA PORT amp OxOf and write upper nibble DATA PORT DDaddr 0b10000000 amp Oxf0 2001 Microchip Technology Inc DS39024B page 49 PICDEM 17 Demonstration Board User s Guide else Lower nibble interface TRIS DATA PORT amp 0xf0 Make port output DATA PO
55. by calling the interrupt handling function goto PIV 2 _PIV 1 BANKSEL fpPIV movfp fpPIV 1 PCLATH movfp fpPIV PCL _PIV 2 call _PIV 1 push address of next instruction on stack Restore WREG and BSR clrf BSR 1 BSR was saved in bank 0 movfp save BSR BSR Now restore it movfp save WREG WREG and WREG as well Restore PCLATH and ALUSTA movfp save PCLATH PCLATH movfp save ALUSTA ALUSTA Return from interrupt RETFIE DS39024B page 32 2001 Microchip Technology Inc Using the MPLAB C17 C Compiler 4 6 Other Files One additional file required to compile programs for the PICDEM 17 demonstration board is the associated processor object module For the PIC17C756A microcontroller this file would be P17C756 ASM This file would need to be assembled to an object file by a MPASM assembler and linked in with the rest of the files The only other file that might be used to compile programs for the PICDEM 17 demonstration board may be the library object module For the PIC17C756A microcontroller the library file PMC756L LIB would be linked with the rest of the files Note 1 User should refer to MPLAB IDE document that shows project setup but special version of linker scripts etc are used here because of the demonstration board requirements 2 Also refer to the MPLAB C17 C Compiler User s Guide DS51112 for additional information 2001 Microchip Technology Inc DS39024B page 33 PICDEM 17
56. d a HEX file to the PICDEM 17 demonstration board first click on Download This will open a Select HEX file window that allows the selection of the desired HEX file to load into the external FLASH program memory on the PICDEM 17 Select HEX file 2 x Lookin A Masters e e sl a LabT hex ia Lab2 hex la Lab3 hex aa Lab4 hex la Lab5 hex Files oftype Hexfiles Y CH I Open es read only Figure 2 2 Select HEX file Window Once a HEX file has been selected for downloading to the PICDEM 17 demonstration board the Monitor will show a Downloading status window that has a bar graph display of percentage download of the file Initially there will be a slight pause allowing the PIC17C756A to erase the FLASH memory 2001 Microchip Technology Inc DS39024B page 9 PICDEM 17 Demonstration Board User s Guide 0 50 100 LLLI Figure 2 3 Downloading Window At the completion of the download the Monitor status window will have displayed a Erasure Complete and Download Complete message When the message window shows a it is ready to process the next command 2 8 Running HEX files from the PICDEM 17 Demonstration Board The Monitor program has a Run button that starts the execution of code from the external FLASH program memory Once a program has been downloaded into the FLASH memory click the Run button to start execution Control of the PIC17C756A is release
57. d by the Monitor firmware by simply writing 4000h to the PCLATH PCL registers Refer to Chapter 4 Using the MPLAB C17 C Compiler tor more information PICDEM 17 Monitor v1 00 Source file filename Modify memory ua Address T Proorem me Vaie Read me Messages Download Complete gt F Erasure Complete Download Complete sil Figure 2 4 Program Running on PICDEM 17 Demonstration Board The only way to stop the program from running is to click on the Reset button in the Monitor window This resets the PIC17C756A and restores operation to the Monitor firmware This method allows for all Data memory interrupt vectors and stack locations to be available to the user for the target application DS39024B page 10 2001 Microchip Technology Inc Using the PICDEM 17 Monitor 2 9 Running Diagnostics on the PICDEM 17 Demonstration Board The Monitor firmware on the PIC17C756A provides several diagnostic routines that allow the user to run pretested code on a peripheral The diagnostics include A D The A D diagnostic allows the user to configure the A D channel clock source justification and reference The A D results are displayed in the Monitor message window During A C Diagnostics the switches and LEDs take on the following functions S5 Increment channel number 0 11 only S9 Toggle between internal and external voltage references 10 Toggle between right and left justify
58. dddd represents the data at that address in HEX format For this operation the first four digits in the Address edit box are used when the command is sent to the PICDEM 17 demonstration board Any additional digits are ignored DS39024B page 16 O 2001 Microchip Technology Inc Using the PICDEM 17 Monitor PICDEM 17 Monitor v1 00 Source file filename Erase Diagnostics Cepture Flash lec PWM Switches x Modify memory C Data memory Address Program memory Value Messages v1 01 00 gt RD011 DF gt WD150aa 2 RP4000 B044 2 WP4000b067 Figure 2 9 Writing Program Memory To write to a Program memory location the user must first select the Program Memory radio button in the Modify Memory window of the Monitor program Then the Program memory address must be written into the Address edit box The format of this value is xxxx where xxxx is a value from 0000h to FFFFh that indicates the desired address within the bank to write The user must also enter the value to be written to the program memory location in the Value edit box Then click the Write button The message window will reply with the following message WPxxxxdddd xxxx represents the program memory address and dddd represents the data written to the address in HEX format For this operation the first four digits of both the Address edit box and the Value edit box are used when the command is sent to the PIC
59. e SIERO V ve AVDD yg 7 s voros 2m S 1 fo ko ne voro7 22 fa E D s aL voros Ht ga J4 3 3 Un vo os te sho abo En vora ts Hine vv 4PHOR 4PHOR au vora n 4 En voa im if EE a_n 2 2 a_i TN sho Lo reno EY L GAL26CV12 4PHOR 4PHDR R10 R11 R VW Re E 1K S13 t m D4 DS J3 J6 SH 545 Ha 02 bi al adn elt gp R H 1N914 1N914 zd J2 es to its nm 7 ms hs rim nilo Le s 7 rim Ep re 8 E L3 mo PA moe Sex Hm mere Se He Pu po pp Gen pa mp Ha am pratt po A p gt LS tara ams mel as peifen U12 Hm ein me een a Pisi 1 im eno po E E pro Pao 22 po TOM Gas TXCAN vec P al el cala PES c32 em ZlpwCan RESET m alas lo alla ra m oe e Zou Cs o Gros pze 28 A ros reten a wP3 ons sol Hien Ll rs EZ rem pi S TXBIRTS SI Lu e ei Zeng al Sen ei ros pale Aneroe vec o TXB2RTS SCK 14 gu ei Alen pol Se aps l pm Ha ani Losc2 INT ls m et ien puts E lps pt LT 9 OSCH RX BF ess n m Es 761 m vss RX1BF MCP2510 DS39024B page 78 O 2001 Microchip Technology Inc PICDEM 17 Demonstration Board Schematics A 4 SCHEMATIC 4
60. e for External Memory programs Linker Script File for External Memory programs Interrupt Service Routines for External Memory programs Source Code Examples 2001 Microchip Technology Inc DS39024B page 83 PICDEM 17 Demonstration Board User s Guide NOTES DS39024B page 84 2001 Microchip Technology Inc Floppy Disk Contents NOTES 2001 Microchip Technology Inc DS39024B page 85 MICROCHIP WORLDWIDE SALES AND SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd Chandler AZ 85224 6199 Tel 480 792 7200 Fax 480 792 7277 Technical Support 480 792 7627 Web Address http www microchip com Rocky Mountain 2355 West Chandler Blvd Chandler AZ 85224 6199 Tel 480 792 7966 Fax 480 792 7456 Atlanta 500 Sugar Mill Road Suite 200B Atlanta GA 30350 Tel 770 640 0034 Fax 770 640 0307 Austin Analog Product Sales 8303 MoPac Expressway North Suite A 201 Austin TX 78759 Tel 512 345 2030 Fax 512 345 6085 Boston 2 Lan Drive Suite 120 Westford MA 01886 Tel 978 692 3848 Fax 978 692 3821 Boston Analog Product Sales Unit A 8 1 Millbrook Tarry Condominium 97 Lowell Road Concord MA 01742 Tel 978 371 6400 Fax 978 371 0050 Chicago 333 Pierce Road Suite 180 Itasca IL 60143 Tel 630 285 0071 Fax 630 285 0075 Dallas 4570 Westgrove Drive Suite 160 Addison TX 75001 Tel 972 818 7423 Fax 972 818 2924 Dayton Two Prestige Place Suite 130 Miamisburg OH 453
61. e register select control line to external LCD PORTG lt 0 1 gt not used PORTG lt 2 gt tied to analog ground PORTG lt 3 gt tied to the 4 096V voltage reference PORTG lt 4 5 gt not used PORTG lt 6 7 gt used for USART2 interface PORTH lt 0 7 gt not used PORTJ lt 0 7 gt not used All VDDs tied to digital 5V all Vss tied to digital ground AVDD tied to analog 5V AVss tied to analog ground 2001 Microchip Technology Inc DS39024B page 19 PICDEM 17 Demonstration Board User s Guide 3 4 Push button Switches The PICDEM 17 demonstration board has a total of nine push button switches S5 S12 are the eight general purpose push button switch inputs that are available to the user S1 is the MCLR reset push button switch that resets the PIC17C7XX 3 5 DIP Switches The PICDEM 17 demonstration board has two sets of DIP switches that control the SPI I C interfaces S13 enables either the I C or SPI I O pins from the microcontroller to the peripherals To use 1 C make sure the positions labeled SDA and SCL are ON and SCK SDO SDI and CS are OFF To use SPI make sure the position labeled SDA and SCL are OFF and SCK SDO SDI and CS are ON The second set of DIP switches S14 routes either the CAN Bus UO or 12C I O to the set of modular connectors This DIP switch is also labeled to SDA SCL for 1 C or CANH CANL for CAN Bus 3 6 RS 232 Interface The PICDEM 17 demonstration board provides a RS 232 interface device U
62. er Write data to LCD up to null while BusyXLCD Wait while LCD is busy WriteDataXLCD buffer Write character to LCD buffer Increment buffer return KKAKKAKKAKAKAKAAKAKAKAKAKAAAAAAAKAKAKAKAKAKAKKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk Function Name OpenXLCD Return Value void Parameters lcdtype sets the type of LCD lines Description his routine configures the LCD Based on the Hitachi HD44780 LCD controller The routine will configure the I O pins of the microcontroller setup the LCD for 4 or 8 bit mode and clear the display The user must provide three delay routines DelayFor18TCY provides a 18 Tcy delay DelayPORXLCD provides at least 15ms delay DelayXLCD provides at least 5ms delay KKAKAKKAKAKAKAAKAAAAAAAAAKAAKAAKAKAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAK void OpenXLCD static unsigned char lcdtype 2001 Microchip Technology Inc DS39024B page 43 PICDEM 17 Demonstration Board User s Guide The data bits must be either a 8 bit port or the upper or lower 4 bits of a port These pins are made into inputs ifdef BIT8 8 bit mode use whole port DATA PORT 0 TRIS DATA PORT Oxff Helse 4 bit mode Hifdef UPPER Upper 4 bits of the port DATA PORT amp Ox0f TRIS DATA PORT 0xf0 Helse Lower 4 bits of the port DATA PORT amp Oxf0 TRIS DATA PORT 0x0f Hendif Hendi
63. f TRIS RW 0 All control sig nals made outputs TRIS RS 0 TRIS E 0 RW PIN 0 R W pin made low RS PIN 0 Register select pin made low E PIN 0 Clock pin made low Delay for 15ms to allow for LCD Power on reset DelayPORXLCD Setup interface to LCD ifdef BIT8 8 bit mode inter face TRIS DATA PORT 0 Data port output DATA PORT 0000110000 Function set cmd 8 bit interface else 4 bit mode inter face ifdef UPPER Upper nibble interface TRIS DATA PORT amp OxO0f DATA PORT amp Ox0f DATA PORT 0b00110000 Function set cmd 4 bit interface else Lower nibble interface TRIS DATA PORT amp 0xf0 DATA PORT amp Oxf0 DATA PORT 0b00000011 Function set cmd 4 bit interface endif endif E PIN 1 Clock the cmd in DelayFor18TCY E_PIN 0 Delay for at least 4 1ms DelayXLCD FEN DS39024B page 44 2001 Microchip Technology Inc LCD C Description Setup interface to LCD ifdef BITS DATA PORT 0b00110000 cmd 8 bit interface else ifdef UPPER interface DATA PORT amp Ox0f cmd 4 bit interface DATA PORT 0b00110000 else interface DATA PORT amp Oxf0 cmd 4 bit interface DATA PORT 0b00000011 endif endif E_PIN 1 DelayFor18TCY E_PIN 0 Delay for at least 100us DelayXLCD Setup interface to LCD ifdef BIT8 DATA PORT 0b00110000 cmd 8 bit inte
64. from DigiKey 2001 Microchip Technology Inc DS39024B page 5 PICDEM 17 Demonstration Board User s Guide 1 14 CAN Bus Interface The PICDEM 17 demonstration board provides a simple interface to a CAN Bus The Microchip Technology MCP2510 CAN Interface peripheral device with the Phillips PCA82C250 device provide a complete CAN Interface solution The two modular connectors J4 and J5 allow easy interface to the bus The canned oscillator socket O2 provides the clock source for the MCP2510 which in turn can also provide the clock source for the PIC17C7XX 1 15 24LC01B Serial EEPROM The PICDEM 17 demonstration board has a 24LC01B Serial EEPROM capable of holding 128 bytes of data This device uses the 12C interface on the PIC17C7XX PICmicro MCU The modular connectors J4 and J5 can also be used to create an I C interface to a peripheral not located on the board 1 16 Modular Connectors The modular connectors J4 and J5 are used to connect to external busses The DIP switch S14 is used to determine if the CAN Bus interface is used or the 12C interface If the CAN Bus is the desired interface the user will have to populate the board with the MCP2510 CAN Bus peripheral from Microchip Technology and the PCA82C250 CAN Bus interface device from Philips Semiconductor Since the MCP2510 uses the SPI interface DIP switch S13 must be configured for SPI SCK SDO SDI CS 1 17 Pre programmed Sample A pre programmed PIC17C756 or
65. gister in the Value edit box Then click the Write button The message window will reply with the following message WDbxxdd bxx represents the bank and address and dd represents the data written to the address in HEX format For this operation the first three digits in the Address edit box and first two digits in the Value edit box are used when the command is sent to the PICDEM 17 demonstration board Any additional digits are ignored 2001 Microchip Technology Inc DS39024B page 15 PICDEM 17 Demonstration Board User s Guide PICDEM 17 Monitor v1 00 x Source file filename Download Erase Run Reset Diagnostics Execute Capture _ Flash 120 Stop PWM E Switches i Modify memory C Data memory Address 4000 Program memory sto m Messages v1 01 00 A gt RD011 DF gt WD150aa 2 RP4000 B044 a Figure 2 8 Reading Program Memory To read from a Program memory location the user must first select the Program Memory radio button in the Modify Memory window of the Monitor program Then the Program memory address must be written into the Address edit box The format of this value is xxxx where xxxx is a value from 0000h to FFFFh that indicates the desired address within the 64K address space to read Then click the Read button The message window will reply with the following message RPxxxx dddd xxxx represents the program memory address and
66. he PCLATH PCL registers This file would need to be assembled and linked in with the other files in the project p RRR RRR KERR RRR RRR KK ERRE RRE KKK KKK KERR RRR ERRE RAR EKER kkk kkk kkk kkk per PIC17C756A Interrupt Support File Version 1 10 AR Large Model AR PICIDEM 17 Workshop Demo Board Version per c Copyright 1997 Microchip Technology p RRR RRR KERR ke ke ke ke KEK ke RRR KK RK KKK he ke KKK ke e he he ke e ERRE RARE RRR ERK ke kc e he ke e e ke e list p 17c756 Equateg 2 222 5 2 2 22 EA ES s PCL equ 0x02 PCLATH equ 0x03 ALUSTA equ 0x04 BSR equ OxOF WREG equ Ox0A SAVEINT START equ 0x00FC Start of shared region for int saving Hid dd LL LLL ERRE RARE RAR RRA RRA RRA fff s INTSAVE SEC UDATA SAVEINT START Save registers that absolutely need to be saved save BSR RES 1 Used for saving the BSR BANK 0 ONLY save WREG RES 1 WREG SPACE RESERVED ALSO IN ALL BANKS save ALUSTA RES jJ ALUSTA SPACE RESERVED ALSO IN ALL BANKS save_PCLATH RES 1 PCLATH SPACE RESERVED ALSO IN ALL BANKS PRK K KK K K RRA K K AK K K AK KKK KR RARE RAR RRA RARA fff RR s save ALUSTA and save PCLATH are saved in any of the banks We therefore must reserve the corresponding locations in ALL banks Since BSR and WREG are guaranteed to be saved in bank 0 they only need storage locations in bank 0 Bank 1 INTSAVE SEC1 UDATA SAVEINT START 0x101 RES 1 WRE
67. le is the linker script file for the project This file contains the processor dependent objects it is included by the linker script file This file contains the library functions compiled for large memory model it is included by the linker script file This file contains the startup code to initialize the Stack initialize data call the startup function and jump to main This file is the main source code file for the project This header file contains processor specific items This is the header file for delay routines in the library DS39024B page 70 2001 Microchip Technology Inc I c c Description 9 6 12C c Source Code Listing LL BRR RR RR RR RR RR RR RAR RR RR RR RAR RR RRA RR RRA I2C C AAA Rodger Richey Principal Applications Engineer Microchip Technology Incorporated LL BRR RR RK KK KK TR TOR TOR TR TOR TR RAR RRA Re 2 December 1998 Compiled using MPLAB C17 C Compiler V2 20 J BRR RRR RER KK KK IK TOR kok TR TOR TOR k k k RH Re This program reads and writes to the 24LC01B Serial EEPROM using the master mode I2C module PJ The value of the address is written to each address of the EEPROM The program then reads the value out of the EEPROM and prints both the desired value and the read value to the USART2 for display on the Monitor program The address is also displayed on the memory mapped LEDs LL BRR RR kok ok IR kok ok TOR TR TR TR TO
68. ler Parameters void Description This routine reads a data byte from the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine The data is read from the character generator RAM or the display data RAM depending on what the previous SetxxRamAddr routine was called KKAKKAKKAKAKAKAKAKAKAKAKAAKAKAAAAAAKAKAKAKAKAKAKKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk char ReadDataXLCD void char data ifdef BIT8 8 bit interface RS PIN 1 Set the control bits RW PIN 1 DelayForl8TCY E PIN 1 Clock the data out of the LCD DelayForl8TCY data DATA PORT Read the data E PIN 0 RS PIN 0 Reset the control bits RW PIN 0 else 4 bit interface RW_PIN 1 RS_PIN 1 DelayForl8TCY E PIN 1 Clock the data out of the LCD DelayFor18TCY ifdef UPPER Upper nibble interface data DATA PORT amp Oxf0 Read the upper nibble of data else Lower nibble interface data DATA PORT 4 amp Oxf0 read the upper nibble of data endif E PIN 0 Reset the clock line DelayFor18TCY E PIN 1 Clock the next nibble out of the LCD DelayFor18TCY Hifdef UPPER Upper nibble interface data DATA PORT gt gt 4 amp 0x0f Read the lower nibble of data 2001 Microchip Technology Inc DS39024B page 53 PICDEM 17 Demonstration Board User s G
69. m Read Data Mem Read Prog Mem Write Data Mem Write Prog Mem 2001 Microchip Technology Inc DS39024B page 81 PICDEM 17 Demonstration Board User s Guide For Data Memory operations bis the bank number xx is the data memory address ddis the 8 bit data value For Program Memory operations yyyy is the 16 bit address dddd is the 16 bit data DS39024B page 82 2001 Microchip Technology Inc PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Appendix C Floppy Disk Contents C 1 INTRODUCTION This appendix provides a listing and description of all files included on the 3 5 floppy disk C 2 CONTENTS The floppy disk includes the following files DIAG C FLASH C FUNCDEFS H INTMONL ASM 17C756L LKR TESTLCD C UTIL C XLCD C XLCD H COL17 ASM PMC756L LIB P17C756 ASM 756MON C 756MON H 756MON RC 756MON EXE PICDEM 17 Files COL17DEM ASM DEMO756L LKR INT756LD ASM LCD C USART C ANALOGC SWITCH C 12C C XLCD C XLCD H PICDEM 17 PIC17C756 Monitor Firmware Diagnostic Routines External FLASH Routines Function Declarations Interrupt Service Routine Linker Script File Main Source Code File Utility Routines External LCD Routines External LCD Header File Startup File Library Routines Processor Definition File PICDEM 17 PC Monitor Software Source Code Header File Resource File Executable Startup Fil
70. mory address somewhere in the first two pages of memory AAA PIC17C756A MPLAB C v2 0 Linker Script File Version 1 10 Large Model For the PICDEM 17 Workshop Demo Board c Copyright 1997 Microchip Technology J BRR ok kok ok kok ok kok kok ok oko IR IR TOR TOR TOR TR TCR TCR TR TR IR Ke Add other files to the project FILESp17c756 0 FILESpmc7561 1ib ROM area for reset amp interrupt vectors CODEPAGE PROTECTED NAME VECTORS START 0x4000 END 0x4027 User Program memory First two pages are used by on chip monitor program CODEPAGE NAME PAGEO START 0x0028 END 0x1FFF CODEPAGE NAME PAGE1 START 0x2000 END 0x3FFF Your program starts in page 2 First 28h locations of page 2 are vectors CODEPAGE NAME PAGE2 START 0x4028 END 0x5FFF CODEPAGE NAME PAGE3 START 0x6000 END 0x7FFF CODEPAGE NAME PAGE4 START 0x8000 END 0x9FFF CODEPAGE NAME PAGE5 START 0xA000 END 0xBFFF CODEPAGE NAME PAGE6 START 0xC000 END 0xDFFF CODEPAGE NAME PAGE7 START 0xE000 END 0xFFFF Special Function registers 1 SFRs that are shared 0x00 to Ox0F REBANK PROTECTE NAME SFRShareA START 0x000 END 0x00F REBANK PROTECTE NAME SFRShareA START 0x100 END 0x10F REBANK PROTECTE NAME SFRShareA START 0x200 END 0x20F REBANK PROTECTE NAME SFRShareA START 0x300 END 0x30F T ij ij mm mmm mp U a GEESS GGG D a mi ki e ax HAREBANK PROTECTE NAME SFRShareA START 0x400 END 0x40F HAREBANK PROTECTE NA
71. n function This file would need to be assembled and linked in with the other files in the project p RRR RRR KERR ke ce RRR RRE RK ke ke KKK KKK KKK ke e e he ke e he KR EK KR RK RARA ke e e he e ke AR PIC17Cxx MPLAB C v2 0 Assembly Startup File Version 1 10 pk Large Model AR PICDEM 17 Workshop Demo Board Version P c Copyright 1997 Microchip Technology HE Soul do RARA ERRE RARE RRA RR RARE kkk kkk kkk kkk kkk kkk This is the C startup assembly file for the large model Please refer to chapter 3 in the user s guide for more information The following two statements determine whether you wish to use initialized data in your C programs and whether you wish to have a STARTUP function called upon reset Please note that if you turn USE STARTUP on then you must defined a _ STARTUP in your code or you will get a linker error DEFINE USE INITDATA Uncomment if you use initialized data DEFINE USE STARTUP Uncomment if you use STARTUP Zeene E QUA EE ele PCL equ 0x02 PCLATH equ 0x03 EXTERN stack EXTERN main IFDEF USE STARTUP EXTERN STARTUP HENDIF HIFDEF USE INITDATA EXTERN copy init data HENDIF po k kk k k k k KR KERR k k KKK ERRE RRE K K K K K K RRA RARA RRA RR LELE RESET CODE H 4000 Location of reset vector IFDEF USE STARTUP movlw HIGH _ STARTUP movwf PCLATH lcall STARTUP HENDIF DS39024B page 26 2001 Microchip Technology Inc Using the MPLAB C17 C Compiler
72. ndia Tel 91 80 2290061 Fax 91 80 2290062 Japan Microchip Technology Intl Inc Benex S 1 6F 3 18 20 Shinyokohama Kohoku Ku Yokohama shi Kanagawa 222 0033 Japan Tel 81 45 471 6166 Fax 81 45 471 6122 Korea Microchip Technology Korea 168 1 Youngbo Bldg 3 Floor Samsung Dong Kangnam Ku Seoul Korea Tel 82 2 554 7200 Fax 82 2 558 5934 ASIA PACIFIC continued Singapore Microchip Technology Singapore Pte Ltd 200 Middle Road 3107 02 Prime Centre Singapore 188980 Tel 65 334 8870 Fax 65 334 8850 Taiwan Microchip Technology Taiwan 11F 3 No 207 Tung Hua North Road Taipei 105 Taiwan Tel 886 2 2717 7175 Fax 886 2 2545 0139 EUROPE Australia Microchip Technology Australia Pty Ltd Suite 22 41 Rawson Street Epping 2121 NSW Australia Tel 61 2 9868 6733 Fax 61 2 9868 6755 Denmark Microchip Technology Denmark ApS Regus Business Centre Lautrup hoj 1 3 Ballerup DK 2750 Denmark Tel 45 4420 9895 Fax 45 4420 9910 France Arizona Microchip Technology SARL Parc d Activite du Moulin de Massy 43 Rue du Saule Trapu Batiment A ler Etage 91300 Massy France Tel 33 1 69 53 63 20 Fax 33 1 69 30 90 79 Germany Arizona Microchip Technology GmbH Gustav Heinemann Ring 125 D 81739 Munich Germany Tel 49 89 627 144 0 Fax 49 89 627 144 44 Germany Analog Product Sales Lochhamer Strasse 13 D 82152 Martinsried Germany Tel 49 89 895650 0 Fax 49 89 895650 22 Italy Arizona Micr
73. ochip Technology SRL Centro Direzionale Colleoni Palazzo Taurus 1 V Le Colleoni 1 20041 Agrate Brianza Milan Italy Tel 39 039 65791 1 Fax 39 039 6899883 United Kingdom Arizona Microchip Technology Ltd 505 Eskdale Road Winnersh Triangle Wokingham Berkshire England RG41 5TU Tel 44 118 921 5869 Fax 44 118 921 5820 01 09 01 All rights reserved 2001 Microchip Technology Incorporated Printed in the USA 1 01 es Printed on recycled paper Information contained in this publication regarding device applications and the like is intended through suggestion only and may be superseded by updates It is your responsibility to ensure that your application meets with your specifications No representation or warranty is given and no liability is assumed by Microchip Technology Incorporated with respect to the accuracy or use of such information or infringement of patents or other intellectual property rights arising from such use or otherwise Use of Microchip s products as critical components in life support systems is not authorized except with express written approval by Microchip No licenses are conveyed implicitly or otherwise except as maybe explicitly expressed herein under any intellec tual property rights The Microchip logo and name are registered trademarks of Microchip Technology Inc in the U S A and other countries All rights reserved All other trademarks mentioned herein are the property of their respective companies
74. ock line RW PIN 0 Reset control line return 1 Return TRUE else Bit 7 low E PIN 0 Reset clock line RW PIN 0 Reset control line return 0 Return FALSE else 4 bit interface ifdef UPPER Upper nibble interface if DATA_PORT amp 0x80 Helse Lower nibble interface if DATA_PORT amp 0x08 endif E PIN 0 Reset clock line DelayFor18TCY E PIN 1 Clock out other nibble DelayFor18TCY E PIN 0 RW_PIN 0 Reset control line return 1 Return TRUE else Busy bit is low E PIN 0 Reset clock line DelayFor18TCY E PIN 1 Clock out other nibble DelayFor18TCY E PIN 0 RW_PIN 0 Reset control line return 0 Return FALSE endif KKAKKAKAKAKAAAAAAAAAAAAAKAAKAKAKAKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAK Kk Function Name ReadAddrXLCD Return Value char address from LCD controller Parameters void Description This routine reads an address byte from the Hitachi HD44780 LCD controller The user 2001 Microchip Technology Inc DS39024B page 51 PICDEM 17 Demonstration Board User s Guide must check to see if the LCD controller is busy before calling this routine The address is read from the character generator RAM or the display data RAM depending on what the previous SetxxRamAddr routine was called KKAKAKKAKAKAKAAKAAKAAAAAAAAAKAKAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
75. ogy Incorporated in the U S A and other countries Total Endurance In Circuit Serial Programming ICSP Filter Lab FlexROM fuzzyLAB ICEPIC microlD MPASM MPLIB MPLINK MXDEV PICDEM and Migratable Memory are trademarks of Microchip Technology Incorporated in the U S A Serialized Quick Term Programming SQTP is a service mark of Microchip Technology Incorporated in the U S A All other trademarks mentioned herein are property of their respective companies 2001 Microchip Technology Incorporated Printed in the U S A All Rights Reserved Microchip received QS 9000 quality system certification for its worldwide headquarters design and wafer fabrication facilities in Chandler and Tempe Arizona in July 1999 The Company s quality system processes and procedures are QS 9000 compliant for its PICmicro 8 bit MCUs KEELOQ code hopping devices Serial EEPROMs and microperipheral products In addition Microchip s quality system for the design and manufacture of development systems is ISO 9001 certified DS39024B 2001 Microchip Technology Inc AN PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Table of Contents PREFACE Welcome E 1 Documentation Layout RE 1 Chapter 1 About PICDEM 17 Demonstration Board It a Tee EE 3 A AAA A 3 1 93 ee 3 1 4 External FLASH Memory i 4 1 5 MemoneMappind i Eesen 4 1 6 POWOr SUP die ieee t a Ep EE 4 Tu Prototyping A ka ea ddd
76. ox The format of this value is bxx where b is a valid bank number in HEX format and xx is a value from 00h to FFh that indicates the desired address within the bank to read Then click the Read button The message window will reply with the following message RDbxx dd bxx represents the bank and address and dd represents the data found at that address in HEX format For this operation the first three digits in the Address edit box are used when the command is sent to the PICDEM 17 demonstration board Any additional digits are ignored DS39024B page 14 2001 Microchip Technology Inc Using the PICDEM 17 Monitor PICDEM 17 Monitor v1 00 eix Source file filename Download Erase Pun Reset r Diagnostics E Execute Capture Flash lec Stop I PWM a Switches xj Modify memory Data memory Address 150 C Program memory Value es Read Write r Messages Boot Mon E v1 01 00 2 RD011 DF gt WD150aa il Figure 2 7 Writing Data Memory To write to a Data memory location the user must first select the Data Memory radio button in the Modify Memory window of the Monitor program Then the Data memory address must be written into the Address edit box The format of this value is bxx where b is a valid bank number in HEX format and xx is a value from 00h to FFh that indicates the desired address within the bank to write The user must also enter the value to be written to the Data re
77. re in the PIC17C756A The Monitor program has many features including Resetting the PIC17C756A on the PICDEM 17 demonstration board Erasing the FLASH on the PICDEM 17 demonstration board Downloading HEX files to the PICDEM 17 demonstration board Running and halting the operation of programs Running diagnostics on the various PIC17C756A peripherals Reading and writing to Data Memory and external FLASH program memory Displaying USART2 activity in message window DS39024B page 8 2001 Microchip Technology Inc Using the PICDEM 17 Monitor 2 5 Resetting the PICDEM 17 Demonstration Board One unique feature of USART2 is the ability to reset the PICmicro MCU This is accomplished by connecting the DTR signal from P2 to the MCLR pin of the PICmicro MCU using the circuit in Figure 2 4 Jumper J3 is also provided to disable this feature To reset the microcontroller simply click on Reset in the Monitor window The boot message should display on the message area 2 6 Erasing the FLASH on the PICDEM 17 Demonstration Board The Monitor program allows the external FLASH program memory device to be erased by clicking on the Erase button This simply erases the FLASH memory When a download is requested the PIC17C756A automatically erases the FLASH Therefore it is not required that the FLASH be erased using the Erase button before a download is initiated 2 Downloading HEX Files to the PICDEM 17 Demonstration Board To downloa
78. rface else ifdef UPPER interface DATA PORT amp Ox0f cmd 4 bit interface DATA PORT 0b00110000 else interface DATA PORT amp Oxf0 cmd 4 bit interface DATA PORT 0b00000011 endif endif E_PIN 1 DelayFor18TCY E_PIN 0 DelayXLCD ifndef BIT8 ifdef UPPER interface DATA PORT amp OxO0f cmd 4 bit interface DATA PORT 0b00100000 else interface DATA PORT amp Oxf0 cmd 4 bit interface DATA PORT 0b00000010 endif 8 bit interface Function set 4 bit interface Upper nibble Function set Lower nibble Function set Clock the cmd in 8 bit interface Function set 4 bit interface Upper nibble Function set Lower nibble Function set Clock cmd in Upper nibble Function set Lower nibble Function set 2001 Microchip Technology Inc DS39024B page 45 PICDEM 17 Demonstration Board User s Guide E PIN 1 Clock cmd in DelayFor18TCY E_PIN 0 endif ifdef BIT8 8 bit interface TRIS DATA PORT 0xff Make data port input else 4 bit interface ifdef UPPER Upper nibble interface TRIS DATA PORT 0xf0 Make data nibble input else Lower nibble interface TRIS DATA PORT 0x0f Make data nibble input endif endif Set data interface width lines font while BusyXLCD
79. switches are not connected directly to I O pins on the microcontroller but are memory mapped into the address space The switches are available at address FFFCh 1 11 LEDs The PICDEM 17 demonstration board also has 8 LEDs which are also memory mapped These LEDs may be accessed at address FFFDh There is no read capability for the LEDs so the user must have a shadow register in the PIC17C7XX device to keep track of the value on the latch 1 12 Analog Circuitry In addition to the power and ground planes on the PICDEM 17 demonstration board it also has separate analog and digital power supplies Both of these voltage regulators use connector J1 as the source If the user desires to power the board from the test points in the prototyping areas then both sets of test points in the analog and digital must be used Otherwise one portion of the board will not be operational 1 13 External LCD Interface The PICDEM 17 demonstration board provides an interface to an external LCD display that uses the Hitachi HD4478 LCD controller or equivalent device The LCD is used in the 4 bit interface mode Four data lines and three control lines are required to operate the LCD These LCD signals are multiplexed with some of the A D converter channels It is therefore important that the A D is properly initialized before the LCD can be used refer to Chapter 4 The board layout provides space for the Optrex DMC 50448N 8x2 character display which is available
80. turn linefeed string crlf 0 0x0d crlf 1 0x0a crlf 2 0 Initialize USART2 and the hardware handshaking lines PORTBbits RB5 1 DDRBbits RB5 0 2001 Microchip Technology Inc DS39024B page 63 PICDEM 17 Demonstration Board User s Guide OpenUSART2 USART TX INT OFF amp USART RX INT OFF amp USART ASYNCH MODE amp USART EIGHT BIT amp USART CONT RX 25 Initialize the A D OpenADC ADC INT OFF amp ADC FOSC 32 amp ADC RIGHT JUST amp ADC VREF INT amp ADC 4ANA 8DIG ADC CHO Print a carriage return and linefeed PutsUSART2 crlf while 1 ConvertADC Start a conversion while BusyADC Wait to complete result ReadADC Read result uitoa result str Convert to ASCII PutsUSART2 str Print string to USART PutsUSART2 crlf Print crlf to USART Delayl0KTCYx 250 Wait a while Delayl0KTCYx 250 DS39024B page 64 2001 Microchip Technology Inc AN PICDEM 17 DEMONSTRATION MICROCHIP BOARD USER S GUIDE Chapter 8 SWITCH C Description 8 1 Introduction This chapter describes the demonstration program for the PIC17C756A SWITCH C This program first turns on all the memory mapped LEDs When the corresponding pushbutton switch is pressed the microcontroller will toggle the state of the LED 8 2 Highlights This chapter covers the following topics MPLAB IDE Project Files PICmicro C Libraries Source Code Descriptions SWITCH C
81. uide else Lower nibble interface data DATA PORT amp OxOf Read the lower nibble of data endif E_PIN 0 RS_PIN 0 Reset the control bits RW_PIN 0 endif return data Return the data byte KKAKAKKAKAKAAAKAAAAKAAAAKAAKAAKAKAKAKAKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKk Function Name WriteDataXLCD Return Value void Parameters data data byte to be written to LCD Description This routine writes a data byte to the Hitachi HD44780 LCD controller The user must check to see if the LCD controller is busy before calling this routine The data is written to the character generator RAM or the display data RAM depending on what the previous SetxxRamAddr routine was called KKAKAKKAKAAKAAKAAAAAAAAKAAKAKAKAKAKAKAKAKKAKKAKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKAKk void WriteDataXLCD static char data while BusyXLCD ifdef BIT8 8 bit interface TRIS DATA PORT 0 Make port output DATA PORT data Write data to port RS PIN 1 Set control bits RW PIN 0 DelayFor18TCY E PIN 1 Clock data into LCD DelayForl8TCY E PIN 0 RS PIN 0 Reset control bits TRIS DATA PORT Oxff Make port input else 4 bit interface ifdef UPPER Upper nibble interface TRIS DATA PORT amp OxO0f DATA PORT amp Ox0f DATA PORT data amp 0xf0 else Lower nibble interface TRIS DATA PORT

Download Pdf Manuals

image

Related Search

Related Contents

ICY BOX IB-111U3-Hub    説明書 - Butterfly System  kastens für Verteilte Algorithmen  取扱説明書 パーキンスブレイラー ネクストジェネレーション  MultiSync MT840/MT1040/MT1045 Projecteur LCD Manuel d  N°172 - Février 2011 A la une : Solidaires  OM, Rider 11 R, Rider 11 C, Rider 13 C, Rider 16 C  H990取扱説明書  mig/mag • tig • mma gb ifdep nl dk sf ns gr ru h ro pl cz sk  

Copyright © All rights reserved.
Failed to retrieve file