|
|
|
Bonjour a tous.
Voila je viens de finir un programme dans le cadre d'un cour du lycée et je souhaiterai le passer en algoritme mais je ne sais pas comment faire.Pouvez vous m'aider s'il vous plait?me donner des astuces.Merci d'avance a toute l'equipe de télécharger.com .
voici le code :
/*
* This is example 1 from "Getting Started with MPLAB C18".
*/
#include <p18f2620.h> /* for TRISB and PORTB declarations */
//#include "C:\cao\Viewlogic\fusee\Logiciels\i2c.h"
#include <i2c.h>
#include "C:\cao\Viewlogic\Gestion LCD\AfficheurLCD.h"
#pragma config OSC = INTIO7 /* CLKOUT sur RA6*/
#pragma config WDT = OFF
#pragma config LVP = OFF
#ifdef __EXTENDED18__ // Pour compilation en mode étendu
#pragma config XINST = ON
#else
#pragma config XINST = OFF
#endif
// Writes a string from ROM to the USART
//void putrsUSART(const rom char *data);
// ExtEEWrite and ExtEERead are used to read or write an integer value to the
// 24C01 EEPROM
char Write24C64(unsigned char controlW, unsigned char addrH, unsigned char addrL,char dat);
unsigned char Read2464( unsigned char controlR, unsigned char addrH, unsigned char addrL );
//char dat=0;
int Collision, i, j, k, addr=0;
unsigned char addrH, addrL, controlW = 0xA0, controlR = 0xA1,toto;
//char Ligne[1728];
rom far char data[2558] = {
0x3C, 0x68, 0x74, 0x6D, 0x6C, 0x3E, 0x0D, 0x0A, 0x3C, 0x68, 0x65, 0x61, 0x64, 0x3E, 0x0D, 0x0A,
0x3C, 0x6D, 0x65, 0x74, 0x61, 0x20, 0x68, 0x74, 0x74, 0x70, 0x2D, 0x65, 0x71, 0x75, 0x69, 0x76,
0x3D, 0x22, 0x50, 0x72, 0x61, 0x67, 0x6D, 0x61, 0x22, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x65, 0x6E,
0x74, 0x3D, 0x22, 0x6E, 0x6F, 0x2D, 0x63, 0x61, 0x63, 0x68, 0x65, 0x22, 0x3E, 0x0D, 0x0A, 0x3C,
0x6D, 0x65, 0x74, 0x61, 0x20, 0x68, 0x74, 0x74, 0x70, 0x2D, 0x65, 0x71, 0x75, 0x69, 0x76, 0x3D,
0x22, 0x45, 0x78, 0x70, 0x72, 0x69, 0x72, 0x65, 0x73, 0x22, 0x20, 0x63, 0x6F, 0x6E, 0x74, 0x65,
0x6E, 0x74, 0x3D, 0x22, 0x2D, 0x31, 0x22, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x69, 0x74, 0x6C, 0x65,
0x3E, 0x50, 0x61, 0x67, 0x65, 0x20, 0x44, 0x27, 0x65, 0x74, 0x61, 0x74, 0x20, 0x50, 0x69, 0x63,
0x62, 0x61, 0x73, 0x69, 0x63, 0x20, 0x57, 0x65, 0x62, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
0x3C, 0x2F, 0x74, 0x69, 0x74, 0x6C, 0x65, 0x3E, 0x0D, 0x0A, 0x3C, 0x73, 0x74, 0x79, 0x6C, 0x65,
0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x22, 0x74, 0x65, 0x78, 0x74, 0x2F, 0x63, 0x73, 0x73, 0x22,
0x3E, 0x0D, 0x0A, 0x2E, 0x61, 0x66, 0x66, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x42, 0x41, 0x43, 0x4B,
0x47, 0x52, 0x4F, 0x55, 0x4E, 0x44, 0x2D, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x62, 0x6C, 0x61,
0x63, 0x6B, 0x3B, 0x0D, 0x0A, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x6C, 0x69, 0x6D, 0x65, 0x3B,
0x0D, 0x0A, 0x66, 0x6F, 0x6E, 0x74, 0x2D, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3A, 0x62, 0x6F,
0x6C, 0x64, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x2E, 0x6C, 0x65, 0x64, 0x31, 0x0D, 0x0A, 0x7B,
0x0D, 0x0A, 0x42, 0x41, 0x43, 0x4B, 0x47, 0x52, 0x4F, 0x55, 0x4E, 0x44, 0x2D, 0x43, 0x4F, 0x4C,
0x4F, 0x52, 0x3A, 0x72, 0x65, 0x64, 0x3B, 0x0D, 0x0A, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x62,
0x6C, 0x61, 0x63, 0x6B, 0x3B, 0x0D, 0x0A, 0x66, 0x6F, 0x6E, 0x74, 0x2D, 0x77, 0x65, 0x69, 0x67,
0x68, 0x74, 0x3A, 0x62, 0x6F, 0x6C, 0x64, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x2E, 0x6C, 0x65,
0x64, 0x30, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x42, 0x41, 0x43, 0x4B, 0x47, 0x52, 0x4F, 0x55, 0x4E,
0x44, 0x2D, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x73, 0x69, 0x6C, 0x76, 0x65, 0x72, 0x3B, 0x0D,
0x0A, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x62, 0x6C, 0x61, 0x63, 0x6B, 0x3B, 0x0D, 0x0A, 0x66,
0x6F, 0x6E, 0x74, 0x2D, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x3A, 0x62, 0x6F, 0x6C, 0x64, 0x3B,
0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x2E, 0x4C, 0x43, 0x44, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x42, 0x41,
0x43, 0x4B, 0x47, 0x52, 0x4F, 0x55, 0x4E, 0x44, 0x2D, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x23,
0x36, 0x41, 0x44, 0x35, 0x30, 0x30, 0x3B, 0x0D, 0x0A, 0x43, 0x4F, 0x4C, 0x4F, 0x52, 0x3A, 0x62,
0x6C, 0x61, 0x63, 0x6B, 0x3B, 0x0D, 0x0A, 0x66, 0x6F, 0x6E, 0x74, 0x2D, 0x77, 0x65, 0x69, 0x67,
0x68, 0x74, 0x3A, 0x62, 0x6F, 0x6C, 0x64, 0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x74, 0x64, 0x0D,
0x0A, 0x7B, 0x0D, 0x0A, 0x77, 0x69, 0x64, 0x74, 0x68, 0x3A, 0x31, 0x35, 0x30, 0x0D, 0x0A, 0x7D,
0x0D, 0x0A, 0x3C, 0x2F, 0x73, 0x74, 0x79, 0x6C, 0x65, 0x3E, 0x0D, 0x0A, 0x3C, 0x73, 0x63, 0x72,
0x69, 0x70, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x22, 0x74, 0x65, 0x78, 0x74, 0x2F, 0x6A,
0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x22, 0x3E, 0x0D, 0x0A, 0x66, 0x75, 0x6E,
0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x74, 0x28, 0x6F, 0x62, 0x6A, 0x29, 0x0D, 0x0A, 0x7B, 0x0D,
0x0A, 0x69, 0x66, 0x28, 0x6F, 0x62, 0x6A, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x2E, 0x6C, 0x65,
0x6E, 0x67, 0x74, 0x68, 0x3E, 0x33, 0x32, 0x29, 0x0D, 0x0A, 0x6F, 0x62, 0x6A, 0x2E, 0x76, 0x61,
0x6C, 0x75, 0x65, 0x3D, 0x6F, 0x62, 0x6A, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x2E, 0x73, 0x75,
0x62, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x28, 0x30, 0x2C, 0x33, 0x32, 0x29, 0x3B, 0x0D, 0x0A,
0x7D, 0x0D, 0x0A, 0x0D, 0x0A, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x65, 0x6E,
0x76, 0x28, 0x29, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x61, 0x3D, 0x22, 0x22,
0x3B, 0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x62, 0x3D, 0x64, 0x6F, 0x63, 0x75, 0x6D, 0x65, 0x6E,
0x74, 0x2E, 0x66, 0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x46, 0x32, 0x3B, 0x0D, 0x0A, 0x66, 0x6F, 0x72,
0x20, 0x28, 0x69, 0x3D, 0x30, 0x3B, 0x69, 0x3C, 0x34, 0x3B, 0x69, 0x2B, 0x2B, 0x29, 0x20, 0x69,
0x66, 0x20, 0x28, 0x64, 0x6F, 0x63, 0x75, 0x6D, 0x65, 0x6E, 0x74, 0x2E, 0x66, 0x6F, 0x72, 0x6D,
0x73, 0x2E, 0x46, 0x31, 0x2E, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E, 0x74, 0x73, 0x5B, 0x27, 0x4F,
0x27, 0x2B, 0x69, 0x5D, 0x2E, 0x63, 0x68, 0x65, 0x63, 0x6B, 0x65, 0x64, 0x3D, 0x3D, 0x74, 0x72,
0x75, 0x65, 0x29, 0x20, 0x61, 0x3D, 0x61, 0x2B, 0x31, 0x3B, 0x20, 0x65, 0x6C, 0x73, 0x65, 0x20,
0x61, 0x3D, 0x61, 0x2B, 0x30, 0x3B, 0x0D, 0x0A, 0x62, 0x2E, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E,
0x74, 0x73, 0x5B, 0x27, 0x4F, 0x27, 0x5D, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x61, 0x3B,
0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x54, 0x3D, 0x62, 0x2E, 0x65, 0x6C, 0x65, 0x6D, 0x65, 0x6E,
0x74, 0x73, 0x5B, 0x27, 0x54, 0x27, 0x5D, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3B, 0x0D, 0x0A,
0x69, 0x66, 0x20, 0x28, 0x54, 0x2E, 0x6C, 0x65, 0x6E, 0x67, 0x74, 0x68, 0x3C, 0x33, 0x32, 0x29,
0x0D, 0x0A, 0x7B, 0x0D, 0x0A, 0x66, 0x6F, 0x72, 0x20, 0x28, 0x69, 0x3D, 0x54, 0x2E, 0x6C, 0x65,
0x6E, 0x67, 0x74, 0x68, 0x3B, 0x69, 0x3C, 0x33, 0x32, 0x3B, 0x69, 0x2B, 0x2B, 0x29, 0x20, 0x54,
0x3D, 0x54, 0x2B, 0x22, 0x20, 0x22, 0x3B, 0x0D, 0x0A, 0x62, 0x2E, 0x65, 0x6C, 0x65, 0x6D, 0x65,
0x6E, 0x74, 0x73, 0x5B, 0x27, 0x54, 0x27, 0x5D, 0x2E, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x54,
0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x62, 0x2E, 0x73, 0x75, 0x62, 0x6D, 0x69, 0x74, 0x28, 0x29,
0x3B, 0x0D, 0x0A, 0x7D, 0x0D, 0x0A, 0x3C, 0x2F, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x3E, 0x0D,
0x0A, 0x3C, 0x2F, 0x68, 0x65, 0x61, 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x62, 0x6F, 0x64, 0x79, 0x3E,
0x0D, 0x0A, 0x3C, 0x63, 0x65, 0x6E, 0x74, 0x65, 0x72, 0x3E, 0x3C, 0x68, 0x31, 0x3E, 0x50, 0x61,
0x67, 0x65, 0x20, 0x44, 0x27, 0x65, 0x74, 0x61, 0x74, 0x20, 0x50, 0x69, 0x63, 0x62, 0x61, 0x73,
0x69, 0x63, 0x20, 0x57, 0x65, 0x62, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x3C, 0x2F, 0x68,
0x31, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x61, 0x62, 0x6C, 0x65, 0x20, 0x63, 0x65, 0x6C, 0x6C, 0x70,
0x61, 0x64, 0x64, 0x69, 0x6E, 0x67, 0x3D, 0x31, 0x30, 0x20, 0x62, 0x6F, 0x72, 0x64, 0x65, 0x72,
0x3D, 0x31, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x64, 0x3E, 0x0D,
0x0A, 0x3C, 0x42, 0x3E, 0x45, 0x6E, 0x74, 0x72, 0xE9, 0x65, 0x73, 0x20, 0x61, 0x6E, 0x61, 0x6C,
0x6F, 0x67, 0x69, 0x71, 0x75, 0x65, 0x73, 0x3C, 0x2F, 0x42, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x3C,
0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x41, 0x30, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74,
0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
0x41, 0x30, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x41, 0x30, 0x22, 0x20,
0x73, 0x69, 0x7A, 0x65, 0x3D, 0x35, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x61, 0x66, 0x66,
0x20, 0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x20, 0x76, 0x3C, 0x62, 0x72, 0x3E,
0x0D, 0x0A, 0x41, 0x31, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79,
0x70, 0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x41, 0x31, 0x20,
0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x41, 0x31, 0x22, 0x20, 0x73, 0x69, 0x7A,
0x65, 0x3D, 0x35, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x61, 0x66, 0x66, 0x20, 0x72, 0x65,
0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x20, 0x76, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x41,
0x32, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D,
0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x41, 0x32, 0x20, 0x76, 0x61, 0x6C,
0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x41, 0x32, 0x22, 0x20, 0x73, 0x69, 0x7A, 0x65, 0x3D, 0x35,
0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x61, 0x66, 0x66, 0x20, 0x72, 0x65, 0x61, 0x64, 0x6F,
0x6E, 0x6C, 0x79, 0x3E, 0x20, 0x76, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x41, 0x33, 0x20, 0x3D,
0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x74, 0x65, 0x78,
0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x41, 0x33, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D,
0x22, 0x20, 0x24, 0x41, 0x33, 0x22, 0x20, 0x73, 0x69, 0x7A, 0x65, 0x3D, 0x35, 0x20, 0x63, 0x6C,
0x61, 0x73, 0x73, 0x3D, 0x61, 0x66, 0x66, 0x20, 0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79,
0x3E, 0x20, 0x76, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x64, 0x3E, 0x0D, 0x0A,
0x3C, 0x74, 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x42, 0x3E, 0x45, 0x6E, 0x74, 0x72, 0xE9, 0x65, 0x73,
0x20, 0x6C, 0x6F, 0x67, 0x69, 0x71, 0x75, 0x65, 0x73, 0x3C, 0x2F, 0x42, 0x3E, 0x3C, 0x62, 0x72,
0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x49, 0x30, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70,
0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D,
0x65, 0x3D, 0x49, 0x30, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x49, 0x30,
0x22, 0x20, 0x73, 0x69, 0x7A, 0x65, 0x3D, 0x31, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x6C,
0x65, 0x64, 0x24, 0x49, 0x30, 0x20, 0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x3C,
0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x49, 0x31, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74,
0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D,
0x49, 0x31, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x49, 0x31, 0x22, 0x20,
0x73, 0x69, 0x7A, 0x65, 0x3D, 0x31, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x6C, 0x65, 0x64,
0x24, 0x49, 0x31, 0x20, 0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x3C, 0x62, 0x72,
0x3E, 0x0D, 0x0A, 0x49, 0x32, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74,
0x79, 0x70, 0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x49, 0x32,
0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x49, 0x32, 0x22, 0x20, 0x73, 0x69,
0x7A, 0x65, 0x3D, 0x31, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x6C, 0x65, 0x64, 0x24, 0x49,
0x32, 0x20, 0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x0D,
0x0A, 0x49, 0x33, 0x20, 0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70,
0x65, 0x3D, 0x74, 0x65, 0x78, 0x74, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x49, 0x33, 0x20, 0x76,
0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x20, 0x24, 0x49, 0x33, 0x22, 0x20, 0x73, 0x69, 0x7A, 0x65,
0x3D, 0x31, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x3D, 0x6C, 0x65, 0x64, 0x24, 0x49, 0x33, 0x20,
0x72, 0x65, 0x61, 0x64, 0x6F, 0x6E, 0x6C, 0x79, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x3C,
0x2F, 0x74, 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x72,
0x20, 0x76, 0x61, 0x6C, 0x69, 0x67, 0x6E, 0x3D, 0x74, 0x6F, 0x70, 0x3E, 0x0D, 0x0A, 0x3C, 0x74,
0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x66, 0x6F, 0x72, 0x6D, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x46,
0x31, 0x3E, 0x0D, 0x0A, 0x3C, 0x42, 0x3E, 0x53, 0x6F, 0x72, 0x74, 0x69, 0x65, 0x73, 0x20, 0x6C,
0x6F, 0x67, 0x69, 0x71, 0x75, 0x65, 0x73, 0x3C, 0x2F, 0x42, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x3C,
0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x20, 0x74, 0x79, 0x70,
0x65, 0x3D, 0x22, 0x74, 0x65, 0x78, 0x74, 0x2F, 0x6A, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69,
0x70, 0x74, 0x22, 0x3E, 0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x76, 0x3D, 0x6E, 0x65, 0x77, 0x20,
0x41, 0x72, 0x72, 0x61, 0x79, 0x28, 0x22, 0x24, 0x4F, 0x30, 0x22, 0x2C, 0x22, 0x24, 0x4F, 0x31,
0x22, 0x2C, 0x22, 0x24, 0x4F, 0x32, 0x22, 0x2C, 0x22, 0x24, 0x4F, 0x33, 0x22, 0x29, 0x3B, 0x0D,
0x0A, 0x66, 0x6F, 0x72, 0x20, 0x28, 0x6E, 0x3D, 0x30, 0x3B, 0x20, 0x6E, 0x3C, 0x76, 0x2E, 0x6C,
0x65, 0x6E, 0x67, 0x74, 0x68, 0x3B, 0x20, 0x6E, 0x2B, 0x2B, 0x29, 0x0D, 0x0A, 0x7B, 0x0D, 0x0A,
0x69, 0x66, 0x20, 0x28, 0x76, 0x5B, 0x6E, 0x5D, 0x3D, 0x3D, 0x22, 0x31, 0x22, 0x29, 0x20, 0x73,
0x3D, 0x22, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6B, 0x65, 0x64, 0x22, 0x3B, 0x20, 0x65, 0x6C, 0x73,
0x65, 0x20, 0x73, 0x3D, 0x22, 0x22, 0x3B, 0x0D, 0x0A, 0x64, 0x6F, 0x63, 0x75, 0x6D, 0x65, 0x6E,
0x74, 0x2E, 0x77, 0x72, 0x69, 0x74, 0x65, 0x28, 0x22, 0x4F, 0x22, 0x2B, 0x6E, 0x2B, 0x22, 0x20,
0x3D, 0x20, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x27, 0x63,
0x68, 0x65, 0x63, 0x6B, 0x62, 0x6F, 0x78, 0x27, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x27, 0x4F,
0x22, 0x2B, 0x6E, 0x2B, 0x22, 0x27, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x27, 0x31, 0x27,
0x22, 0x2B, 0x73, 0x2B, 0x22, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x22, 0x29, 0x3B, 0x0D, 0x0A, 0x7D,
0x0D, 0x0A, 0x3C, 0x2F, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74,
0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x64, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x66, 0x6F, 0x72, 0x6D,
0x3E, 0x0D, 0x0A, 0x3C, 0x42, 0x3E, 0x45, 0x63, 0x72, 0x61, 0x6E, 0x20, 0x4C, 0x43, 0x44, 0x3C,
0x2F, 0x42, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x66, 0x6F,
0x72, 0x6D, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x46, 0x32, 0x20, 0x6D, 0x65, 0x74, 0x68, 0x6F,
0x64, 0x3D, 0x67, 0x65, 0x74, 0x3E, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70,
0x65, 0x3D, 0x68, 0x69, 0x64, 0x64, 0x65, 0x6E, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x4F, 0x20,
0x76, 0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x22, 0x3E, 0x0D, 0x0A, 0x3C, 0x74, 0x65, 0x78, 0x74,
0x61, 0x72, 0x65, 0x61, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x54, 0x20, 0x72, 0x6F, 0x77, 0x73,
0x3D, 0x32, 0x20, 0x63, 0x6F, 0x6C, 0x73, 0x3D, 0x31, 0x36, 0x20, 0x63, 0x6C, 0x61, 0x73, 0x73,
0x3D, 0x4C, 0x43, 0x44, 0x20, 0x4F, 0x6E, 0x6B, 0x65, 0x79, 0x55, 0x70, 0x3D, 0x22, 0x74, 0x28,
0x74, 0x68, 0x69, 0x73, 0x29, 0x22, 0x20, 0x4F, 0x6E, 0x6B, 0x65, 0x79, 0x44, 0x6F, 0x77, 0x6E,
0x3D, 0x22, 0x74, 0x28, 0x74, 0x68, 0x69, 0x73, 0x29, 0x22, 0x3E, 0x24, 0x54, 0x30, 0x3C, 0x2F,
0x74, 0x65, 0x78, 0x74, 0x61, 0x72, 0x65, 0x61, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x64, 0x3E,
0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x74, 0x61, 0x62, 0x6C, 0x65,
0x3E, 0x0D, 0x0A, 0x3C, 0x73, 0x6D, 0x61, 0x6C, 0x6C, 0x3E, 0x24, 0x43, 0x50, 0x20, 0x63, 0x6F,
0x6E, 0x6E, 0x65, 0x78, 0x69, 0x6F, 0x6E, 0x28, 0x73, 0x29, 0x20, 0x64, 0x65, 0x70, 0x75, 0x69,
0x73, 0x20, 0x6C, 0x61, 0x20, 0x64, 0x65, 0x72, 0x6E, 0x69, 0xE8, 0x72, 0x65, 0x20, 0x72, 0x65,
0x6D, 0x69, 0x73, 0x65, 0x20, 0xE0, 0x20, 0x7A, 0xE9, 0x72, 0x6F, 0x20, 0x64, 0x75, 0x20, 0x73,
0x65, 0x72, 0x76, 0x65, 0x75, 0x72, 0x2E, 0x3C, 0x62, 0x72, 0x3E, 0x0D, 0x0A, 0x3C, 0x62, 0x72,
0x3E, 0x0D, 0x0A, 0x3C, 0x69, 0x6E, 0x70, 0x75, 0x74, 0x20, 0x74, 0x79, 0x70, 0x65, 0x3D, 0x62,
0x75, 0x74, 0x74, 0x6F, 0x6E, 0x20, 0x6E, 0x61, 0x6D, 0x65, 0x3D, 0x45, 0x4E, 0x56, 0x20, 0x76,
0x61, 0x6C, 0x75, 0x65, 0x3D, 0x22, 0x45, 0x4E, 0x56, 0x4F, 0x59, 0x45, 0x52, 0x22, 0x20, 0x4F,
0x6E, 0x43, 0x6C, 0x69, 0x63, 0x6B, 0x3D, 0x22, 0x65, 0x6E, 0x76, 0x28, 0x29, 0x22, 0x3E, 0x0D,
0x0A, 0x3C, 0x2F, 0x66, 0x6F, 0x72, 0x6D, 0x3E, 0x0D, 0x0A, 0x3C, 0x61, 0x20, 0x68, 0x72, 0x65,
0x66, 0x3D, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x77, 0x77, 0x77, 0x2E, 0x72, 0x64,
0x65, 0x6C, 0x65, 0x63, 0x74, 0x72, 0x6F, 0x6E, 0x69, 0x71, 0x75, 0x65, 0x2E, 0x63, 0x6F, 0x6D,
0x22, 0x20, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x3D, 0x22, 0x5F, 0x62, 0x6C, 0x61, 0x6E, 0x6B,
0x22, 0x3E, 0x77, 0x77, 0x77, 0x2E, 0x52, 0x44, 0x45, 0x6C, 0x65, 0x63, 0x74, 0x72, 0x6F, 0x6E,
0x69, 0x71, 0x75, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x3C, 0x2F, 0x61, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F,
0x62, 0x6F, 0x64, 0x79, 0x3E, 0x0D, 0x0A, 0x3C, 0x2F, 0x68, 0x74, 0x6D, 0x6C, 0x3E }; // Pour test ecriture/lecture memoire I2C
void main (void)
{
int counter=0;
unsigned char ValeurLue;
OSCCONbits.IRCF2 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF0 = 0;
ADCON1bits.PCFG3 = 1; // pour avoir RB4 en digital
OpenXLCDb(FOUR_BITS & _2_LINES_5X7);
WriteCmdXLCDb(LIGNE1);//Ligne 1
AffChaine("Test I2C:");
DDRCbits.RC0=0;
DDRCbits.RC1=0;
OpenI2C(MASTER,SLEW_OFF); // Setup MSSP for master I2C
SSPADD = 70; // 100KHz @ 20MHz
// SSPADD = 10;
//********************
//*** Ecriture I2C ***
//********************
for (i=0; i<100; i++)
{
// dat = 0; // Pour effacement memoire I2C
addrL = addr & 0x00ff;
addrH = ((addr>>8)&0x00ff);
addr++;
while(BusyXLCDb());
WriteCmdXLCDb(LIGNE1);
AffChaine("I2C: ");
AffHexa(addrH);
AffChaine("/");
AffHexa(addrL);
while(BusyXLCDb());
WriteCmdXLCDb(LIGNE2);
AffChaine("donnee: ");
AffHexa(data);
// for (k=0;k<=20000;k++);
toto = Write24C64(controlW, addrH, addrL, data);
PORTCbits.RC0 = 1;
while (EEAckPolling( controlW ));
PORTCbits.RC0 = 0;
}
addr = 0;
//*******************
//*** Lecture I2C ***
//*******************
for (i=0;i<100;i++)
{
PORTCbits.RC1 = 0;
addrL = addr & 0x00ff;
addrH = ((addr>>8)&0x00ff);
PORTCbits.RC1 = 0;
ValeurLue = Read2464( controlW, addrH, addrL );
addr++;
PORTCbits.RC1 = 1;
while(BusyXLCDb());
WriteCmdXLCDb(LIGNE1); //Ligne 2
AffChaine("Lecture I2C ");
while(BusyXLCDb());
WriteCmdXLCDb(LIGNE2); //Ligne 2
AffChaine("i:");
AffHexa(i);
AffChaine(" data:");
AffHexa(ValeurLue);
for (k=0;k<=20000;k++);
for (k=0;k<=20000;k++);
for (k=0;k<=20000;k++);
}
while(1);
}
/********************************************************************
* Function Name: AckI2C *
* Return Value: void *
* Parameters: void *
* Description: Initiate ACK bus condition. *
********************************************************************/
#undef AckI2C
void AckI2C( void )
{
SSPCON2bits.ACKDT = 0; // set acknowledge bit state for ACK
SSPCON2bits.ACKEN = 1; // initiate bus acknowledge sequence
}
/********************************************************************
* Function Name: WriteI2C *
* Return Value: Status byte for WCOL detection. *
* Parameters: Single data byte for I2C bus. *
* Description: This routine writes a single byte to the *
* I2C bus. *
********************************************************************/
unsigned char WriteI2C( unsigned char data_out )
{
SSPBUF = data_out; // write single byte to SSPBUF
if ( SSPCON1bits.WCOL ) // test if write collision occurred
return ( -1 ); // if WCOL bit is set return negative #
else
{
while( SSPSTATbits.BF ); // wait until write cycle is complete
return ( 0 ); // if WCOL bit is not set return non-negative #
}
}
/********************************************************************
* Function Name: ReadI2C *
* Return Value: contents of SSPBUF register *
* Parameters: void *
* Description: Read single byte from I2C bus. *
********************************************************************/
unsigned char ReadI2C( void )
{
SSPCON2bits.RCEN = 1; // enable master for 1 byte reception
while ( !SSPSTATbits.BF ); // wait until byte received
return ( SSPBUF ); // return with read byte
}
/********************************************************************
* Function Name: StartI2C *
* Return Value: void *
* Parameters: void *
* Description: Send I2C bus start condition. *
********************************************************************/
#undef StartI2C
void StartI2C( void )
{
SSPCON2bits.SEN = 1; // initiate bus start condition
}
/********************************************************************
* Function Name: StopI2C *
* Return Value: void *
* Parameters: void *
* Description: Send I2C bus stop condition. *
********************************************************************/
#undef StopI2C
void StopI2C( void )
{
SSPCON2bits.PEN = 1; // initiate bus stop condition
}
/********************************************************************
* Function Name: IdleI2C *
* Return Value: void *
* Parameters: void *
* Description: Test and wait until I2C module is idle. *
********************************************************************/
#undef IdleI2C
void IdleI2C( void )
{
while ( ( SSPCON2 & 0x1F ) | ( SSPSTATbits.R_W ) )
continue;
}
/********************************************************************
* Function Name: OpenI2C *
* Return Value: void *
* Parameters: SSP peripheral setup bytes *
* Description: This function sets up the SSP module on a *
* PIC18CXXX device for use with a Microchip I2C *
* EEPROM device or I2C bus device. *
********************************************************************/
void OpenI2C( unsigned char sync_mode, unsigned char slew )
{
SSPSTAT &= 0x3F; // power on state
SSPCON1 = 0x00; // power on state
SSPCON2 = 0x00; // power on state
SSPCON1 |= sync_mode; // select serial mode
SSPSTAT |= slew; // slew rate on/off
#if defined(__18F2455) || defined(__18F2550) || \
defined(__18F4455) || defined(__18F4550)
DDRBbits.RB1 = 1; // Set SCL (PORTB,1) pin to input
DDRBbits.RB0 = 1; // Set SDA (PORTB,0) pin to input
#else
DDRCbits.RC3 = 1; // Set SCL (PORTC,3) pin to input
DDRCbits.RC4 = 1; // Set SDA (PORTC,4) pin to input
#endif
SSPCON1 |= SSPENB; // enable synchronous serial port
}
char Write24C64(unsigned char controlW, unsigned char addrH, unsigned char addrL,char dat)
{
IdleI2C(); // ensure module is idle
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); // wait until start condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
else // start condition successful
{
if ( WriteI2C( controlW ) ) // write byte - R/W bit should be 0
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
if ( WriteI2C( addrH ) ) // write word address for EEPROM
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
if ( WriteI2C( addrL ) ) // data byte for EEPROM
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
if ( WriteI2C( dat ) ) // data byte for EEPROM
{
return ( -3 ); // set error for write collision
}
}
}
else
{
return ( -2 ); // return with Not Ack error condition
}
}
else
{
return ( -2 ); // return with Not Ack error condition
}
}
IdleI2C(); // ensure module is idle
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN ); // wait until stop condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
return ( 0 ); // return with no error
}
/********************************************************************
* Function Name: EEAckPolling *
* Return Value: error condition status *
* Parameters: EE memory control byte *
* Description: Acknowledge polling of I2C EE memory *
* device. This routine can be used for most *
* I2C EE memory device which uses acknowledge *
* polling. *
********************************************************************/
unsigned char EEAckPolling( unsigned char control )
{
IdleI2C(); // ensure module is idle
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); // wait until start condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
else
{
if ( WriteI2C( control ) ) // write byte - R/W bit should be 0
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
while ( SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
RestartI2C(); // initiate Restart condition
while ( SSPCON2bits.RSEN ); // wait until re-start condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
if ( WriteI2C( control ) ) // write byte - R/W bit should be 0
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
}
}
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN ); // wait until stop condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
return ( 0 ); // return with no error
}
/********************************************************************
* Function Name: EERandomRead *
* Return Value: error condition status and/or data byte *
* Parameters: EE memory control byte with R/W set to 1 *
* Description: Reads 1 byte from passed address to EE memory*
* device. This routine can be used for any I2C*
* EE memory device, which only uses 1 byte of *
* address data as in the 24LC01B/02B/04B/08B. *
* *
********************************************************************/
unsigned char Read2464( unsigned char controlW, unsigned char addrH, unsigned char addrL )
{
IdleI2C(); // ensure module is idle
StartI2C(); // initiate START condition
while ( SSPCON2bits.SEN ); // wait until start condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
else
{
if ( WriteI2C( controlW ) ) // write 1 byte
{
return ( -3 ); // return with write collision error
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
if ( WriteI2C( addrH ) ) // write word address for EEPROM
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition received
{
if ( WriteI2C( addrL ) ) // data byte for EEPROM
{
return ( -3 ); // set error for write collision
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT ) // test for ACK condition, if received
{
RestartI2C(); // generate I2C bus restart condition
while ( SSPCON2bits.RSEN );// wait until re-start condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
if ( WriteI2C( controlW+1 ) )// write 1 byte - R/W bit should be 1
{
return ( -3 ); // return with write collision error
}
IdleI2C(); // ensure module is idle
if ( !SSPCON2bits.ACKSTAT )// test for ACK condition, if received
{
SSPCON2bits.RCEN = 1; // enable master for 1 byte reception
while ( SSPCON2bits.RCEN ); // check that receive sequence is over
NotAckI2C(); // send ACK condition
while ( SSPCON2bits.ACKEN ); // wait until ACK sequence is over
StopI2C(); // send STOP condition
while ( SSPCON2bits.PEN ); // wait until stop condition is over
if ( PIR2bits.BCLIF ) // test for bus collision
{
return ( -1 ); // return with Bus Collision error
}
}
else
{
return ( -2 ); // return with Not Ack error
}
}
else
{
return ( -2 ); // return with Not Ack error
}
}
else
{
return ( -2 ); // return with Not Ack error
}
}
else
{
return ( -2 ); // return with Not Ack error
}
}
return ( (unsigned char) SSPBUF ); // return with data
}
|
|