______________________________________________________________________ > < > MAX7221 library v1.02 < > for < > PICos18 release 2.07 < > < > PICos18 - Real-time kernel for PIC18 family < > < > < > www.picos18.com www.pragmatec.net < >______________________________________________________________________< This file contains all necessary informations to use properly the MAX7221 library for PICos18 v2.07. Download the last PICos18 kernel version from www.picos18.com. ______________________________________________________________________ > < > I - Zip file content < >______________________________________________________________________< The max7221 zip file contains : - max7221.c : to use the max7221, 8 bits 7seg - max7221.h : header file - max7221.txt : this file This max7221 need the PICos18 spi driver to work. So please, configure the spi driver first. Place the C and H file in your project directory. Adapt settings properly depending of your max7221 configuration (#define present at the top of the H file). This library is supposed to be use with PICos18 and has been tested with MPLAB 7.22 and C18 v3.00. Do not use this driver at a frequency lower than 8 Mhz (use the PIC18 PLL to increase the internal frequency). ______________________________________________________________________ > < > II - Hardware settings < >______________________________________________________________________< In max7221.h, update the local defintions to match your hardware: /********************************************************************** * ----------------------- MAX7221 USER SETTINGS -------------------------- **********************************************************************/ // Chip select definition #define CS_PORT_MAX7221 PORTB #define CS_BIT_MAX7221 1 In this example the MAX7221 device will be connected to the PORTB1 of the PIC18. Change it if you connect your device to another port. The CS_BIT accept a value from 0 to 7. CD_PORT is a PIC18 register (PORTA, PORTB, ...). ______________________________________________________________________ > < > VI - MAX7221 driver usage < >______________________________________________________________________< In the application task, include the driver header: #include "max7221.h" You also need to include an external reference to the display buffer interface : extern unsigned char MAX7221_display[]; This buffer is 16 bytes long. Only 8 digits are displayed, but the dot (.) char can be included for each digit. See hereafter an basic example : #include "define.h" #include "max7221.h" /********************************************************************** * Definition dedicated to the local functions. **********************************************************************/ #define ALARM_TSK0 0 /********************************************************************** * ------------------------------ TASK0 ------------------------------- * * First task of the tutorial. * **********************************************************************/ TASK(TASK0) { unsigned char consigne = 0; unsigned char i = 0; TRISEbits.TRISE0 = 0; max7221_Init(); max7221_Clear(); SetRelAlarm(ALARM_TSK0, 300, 300); while (1) { WaitEvent(ALARM_EVENT); ClearEvent(ALARM_EVENT); LATEbits.LATE0 = ~LATEbits.LATE0; sprintf(MAX7221_display, "C=%02d", consigne); consigne++; if (consigne == 100) consigne = 0; max7221_SetIntensity(i); // Max is 15 i++; if (i > 15) i = 0; // Entier display refresh with the buffer_display content max7221_DigitRefresh(); } } ______________________________________________________________________ > < > VII - Conclusion < >______________________________________________________________________< This max7221 is provided from the PICos18 web site with other drivers dedicated to other SPI peripherals. Do not hesitate to check periodicaly the www.picos18.com web site in order to download the last versions of PIC18 drivers for PICos18. /* End of File : max7221.txt */