0% ont trouvé ce document utile (0 vote)
238 vues33 pages

Teste

Ce document décrit le code source d'un projet utilisant des matrices LED 8x8, des afficheurs 7 segments et un capteur de température. Le code contient les définitions et configurations nécessaires pour le matériel ainsi que les routines de base pour l'affichage.

Transféré par

samuel@
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
238 vues33 pages

Teste

Ce document décrit le code source d'un projet utilisant des matrices LED 8x8, des afficheurs 7 segments et un capteur de température. Le code contient les définitions et configurations nécessaires pour le matériel ainsi que les routines de base pour l'affichage.

Transféré par

samuel@
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.

#define VERSION "190126"


// Rajout modulation d'intensité a chaque fin de message
// #define VERSION "190124"
// 16MHZ
// nouveau montage mecanique avec 8 modules
// raccordement alim intemodule sens Horizontal pour reduire les longueurs
// all files included
//
// #define VERSION "181225"

// nota : 3,7V mini avec HC06 !


// avec 6 modules Matrix 8x8
// #define VERSION "180413"
// retour à FOSC=8Mhz
// torsade des 2 fils +5 et 0V alimentant les modules

// test avec U=3,2V ..BAD avec 5V


// #define VERSION "171227"
// version 4 modules 8x8 leds
// modif usage variable Speed 2 à 250 pour affichage Matrices
// Rajout RA3 =0 pour Print Time ecart
// #define VERSION "1781224"
//rappel : Init RTC Drapeau en RTC RAM
// if(Read_DS1307(0x3E)==0x20) return;
/*
Commandes dispo:
"Help" ... this liste :
"Msg=" L maxi=122 cars
"TEMP_ON" Affiche la Temperature LM35DZ
"TEMP_OFF"
"Speed=" valeur de 2 à 512
"Eeprom=" Message en eeprom avec indice 1 à 15
"U;04;06;14;04;19;59#" Maj de la RTC
"Demo" affiche tous les messages en EEPROM PIC
*/

// #define VERSION "170101"


// redim buffer à 128 cars

//#define VERSION "161230"


//modif hardware: Rajout R=2,7K pull-Down sur sortie RC0=CS
// evite l'illumination complete des afficheurs à la mise sous tension
// enlevé l'init RTC par defaut

// reamenagement pour choix


// Msg
// Date Time
[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 1/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

// temper

//#define VERSION "161229" // speciale jour de l'An 2017

// #define Version2
// Rajout decompte HMS du jour de l'An
// #define VERSION "161228"level !
// Probleme mesure LM335 .. tres variable ???
// modif : RA2=-Vref=2,5V
// capteur LM335 -50 +100° sur RA0= EA0
// 2730mV at 0°C 2930mV at 20°C
// -Vref=2500mV=VCC/2
// delta= 2,5V pour 1024 bits
// mesures relevées sur LM335
// VCC = 4,940 V -Vref sur RA2 = 2.470V Mesure RA0=2.923V
//_PIC_calculs_datas_2016.xls LM335

#define DIRECTORY "C:\_MikroC\_MesProjets_MikroC\_18F46K22_8_Matrix8x8"


#define PROJECT "18F46K22_MAX7219_8x_Mat_8x8_SPI1_Softw_LM335_DS1307_I2C2.mcppi"
#define SOURCE "_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_special_NOEL_"
#define EEPROM "18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20_eeprom.ihex"
//SPI_MAX7219_8_Matrice_8x8_180410.h

#define PROCESSOR "18F46K22"


#define POWER_SUPPLY "3.7V_mini"

#define FOSC_INTERNE
#define FOSC 16.0
#define BAUD 19200 // UART1
#define Langage Mikroc V 7.10
#define With_UART1
#define DEBUGGING

// Set TEMP_RESOLUTION to the corresponding resolution of used DS18x20 sensor:


// 18S20: 9 (default setting; can be 9,10,11,or 12)
// 18B20: 12
const unsigned short TEMP_RESOLUTION = 12;

//HARDWARE module

// UART RC6 =TX=fil blanc RC7= RX=fil vert Interface Prolific LTTL/USB -> COM12 19200 -> PC XP VBray 2014
// librairies utilisées:
// UART , C_String C_Stdlib Conversions , I2C

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 2/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

// EEPROM :

/* Config bit :
C:\_MikroC\_MesProjets_MikroC\_Max7219_4_matrice8x8\18F46K22_FOSC_Interne_8MHz
CONFIG1H : $300001 : 0x0028
CONFIG2L : $300002 : 0x0018
CONFIG2H : $300003 : 0x003C
CONFIG3H : $300005 : 0x0099
CONFIG4L : $300006 : 0x0080
CONFIG5L : $300008 : 0x000F
CONFIG5H : $300009 : 0x00C0
CONFIG6L : $30000A : 0x000F
CONFIG6H : $30000B : 0x00E0
CONFIG7L : $30000C : 0x000F
CONFIG7H : $30000D : 0x0040
*/

// ac:PIC_pinout_

// ac:SPI_link

/*
HARDWARE :
Miniinthebox 5281696500001
MAX7219 matricielle 8 * 8 en série interfacé huit chiffres a conduit pilote d'affichage pour Arduino
#02816965 3.91 euros
Disolay Leds 8x8 1088AS
ref matrice 8x8 sur le coé droit
RTC DS1307
5 SQ
I2C2 SCL2 sur RD0 Pin 19 ------ vert ---- 4 SCL
I2C2 SDA2 sur RD1 Pin 20 ------ jaune --- 3 SDA
=5v -------------------------------------orange ---2 VCC
0V Gnd -----------------------------------marron --1 GND

+5V ------- Pin 1 MAX7219 #1 Module 8x8 - MAX7219 #2- -- MAX7219 #3---- MAX7219 #4
0V Gnd ------- Pin 2 MAX7219 #1 Module 8x8 - MAX7219 #2- -- MAX7219 #3---- MAX7219 #4
SPI1 SDO RC5 pin 24 ------- Pin 3 MAX7219 #1 Module 8x8 - MAX7219 #2- -- MAX7219 #3---- MAX7219 #4
SPI1 SDIN RC4 pin 23 not used
Select RC0 pin 15 ------- Pin 4 MAX7219 #1 Module 8x8 - MAX7219 #2- -- MAX7219 #3---- MAX7219 #4
SPI1 CLCK RC3 pin 18 ------- Pin 5 MAX7219 #1 Module 8x8 - MAX7219 #2- -- MAX7219 #3---- MAX7219 #4

UART1 TX sur RC6 pin 25 --- blanc RX cordon Prolix


UART1 RX sur RC7 pin 26 --- vert TX cordon Prolix
Gnd 0V ------------------------------ noir Gnd Cordon Prolix
N.C. --rouge +5V USB

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 3/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

// module BlueTooth Linvor (VERT ) @=[Link]


// JY-MCU Power 3,3 à 6V
// Pin 6 STATE
//UART1 .. 25 RC6 --- R=750---fil vert --> Pin 5 TXD 3,3V
//UART1 .. 26 RC7 ------------fil blanc<---Pin 4 RXD
// 0V Gnd ----fil noir---- Pin 3 GND
// +5V -------fil rouge ---Pin 2 VCC
// Pin 1 KEY

UART2 TX sur ED6 pin 29


UART2 RX sur RD7 pin 30

+VCC ----------------------R=2,7K ----Pin1 LM3335 Alim


RA0 Entree Analog pin 2 Pin2 du LM335 Output
0V -------------------R 100K -------- Pin 3 du LM335 adjust
Diviseur par 2 +VCC --- 2,7K --|- 2,7K ---- 0V
RA2 Entree -VREF ------------|

*/

#include "built_in.h" // for Hi Lo ..etc

#define CLS 12
#define CR 13
#define LF 10
#define TAB 9
#define BACK 8
#define Separator 0x20 // space
#define Byte unsigned char

#define NbCycles_T1 8 // nb d'interrupot pour faire 1 seconde

sbit Led_Rouge at LATA4_bit;


sbit Led_Rouge_Dir at TRISA4_bit;

sbit Debug_Time at PORTA.B3;


sbit Debug_Time_Dir at TRISA3_bit;

// Software SPI module connections


sbit SoftSpi_SDI at RC4_bit;
sbit SoftSpi_SDO at RC5_bit;
sbit SoftSpi_CLK at RC3_bit;

sbit SoftSpi_SDI_Direction at TRISC4_bit;


sbit SoftSpi_SDO_Direction at TRISC5_bit;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 4/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

sbit SoftSpi_CLK_Direction at TRISC3_bit;

sbit SPI_CS at LATC0_bit;


sbit SPI_CS_Dir at TRISC0_bit;

sbit SPI_CLOCK at LATC3_bit;


sbit SPI_CLOCK_Dir at TRISC3_bit;
sbit SPI_DOUT at LATC5_bit;
sbit SPI_DOUT_Dir at TRISC5_bit;

const code char mesg0[]=" Mikroc 7.2.0 "PROCESSOR" \r\n";


const code char mesg1[]=" Directory : "DIRECTORY" \r\n";
const code char mesg2[]=" Projet : "PROJECT"\r\n";
const code char mesg3[]=" Source : "SOURCE"_"VERSION".c \r\n";
const code char mesg4[]=" 8 Modules Matrice 8x8 avec MAX7129 + capteur OWS DS18B20\r\n";
const code char mesg5[]=" Saisir un nouveau Msg avec le terminal via <Msg=xxxx>\r\n";
const code char mesg6[]=" Mode Temperature avec <TEMP_ON> ou <TEMP_OFF>\r\n";
const code char mesg7[]=" Messages en EEPROM avec cde : <EEPROM=0> .. à 15 \r\n";
const code char mesg8[]=" Alim ="POWER_SUPPLY"\r\n";
const code char mesg9[]= " ";

const code char * Messages[]={mesg0,mesg1,mesg2,mesg3,mesg4,mesg5,mesg6,mesg7,mesg8,mesg9};

#define MAXLEN2 128


#define MAXLEN_BUFFER1 128
volatile unsigned char buffer1[MAXLEN_BUFFER1];
volatile unsigned int Flag_Buffer1;
volatile unsigned char c1;
volatile unsigned int i1;
volatile unsigned int Index1;
volatile unsigned int CptErr;

volatile int Flag_Timer1;


volatile unsigned int Cpt1;
volatile unsigned int Max_Timer1;

unsigned int i,j,k,l,m,n;


unsigned char TEXTE[MAXLEN2]; // pour teste quelconque
unsigned char TEXTE2[MAXLEN2]; // pour temperature Amb
unsigned char * txt;
unsigned char * txt2;
unsigned char *p1;
unsigned char *p2;
char CRam1[80]; // for flot2asccii use

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 5/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

int nM;
unsigned char N1;
unsigned char addr,donnee;
unsigned int Etat;
unsigned int clk;
unsigned long OverFlow_Timer0;
unsigned long L1,L2;
unsigned char Cpt=0;

unsigned int Pas;


unsigned int Count0;
unsigned int Flag_Timer0=0;

float f1,f2,ff;

// MAX7129 matrice 8x8


unsigned char Aff_buffer[512]; // 8*8=64 + eventuell string terminator=0
unsigned Display_32x8_Pixel[256];
unsigned int Speed=100;

volatile struct chbits { // 8 flags


unsigned FrameErr:1;
unsigned Over:1;
unsigned RTC_Initialise: 1;
unsigned FLT:1;
unsigned PPS:1;
unsigned Temper:1;
unsigned Elapsed_Time:1;
unsigned Mesure:1;
unsigned First_Run:1;
}Drapeaux ;

unsigned char sec, min1, hr, week_day, day, month, year,ctrl;


char tnum[8];
int dummy;
unsigned char Date[14]; // dd/mm/20yy\0
unsigned char Time[10]; // hh:mn:ss\0
unsigned char DateTime[24];
unsigned char DS1307_Started ;

#include "../common/timelib.h"
TimeStruct ts1, ts2 ,ts3;
long epoch=0L ;
long epoch1=0L ;
long epoch2=0L ;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 6/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

long Ecart=0L ;
unsigned char NbH=0;
unsigned char NbM=0;
unsigned char NbS=0;
char Val_Ecart[16];
char Val_epoch1[16];
char Val_epoch2[16];

unsigned long DS18B20_Temp1=0L;


//unsigned
int temp_fraction;
char temp_whole,Signe;
unsigned int tempL=0;
unsigned int temp=0;

unsigned char ID1[7];

// ---------------------------------------

void Init_Hardware(void) ;
void Read_Msg_Eeprom( int depuis);
void Write_Msg_Eeprom( int Adr,const char * d1) ;

void Init_Timer1 (void); // timer 100mS * Max_timer1


void Arme_Timer1(void); //
void Init_Timer0 (void); // counter in RA4 input
void strConstRamCpy(unsigned char *dest, const code char *source);
void UART1_Write_CText(const char *txt);
void RAZ_UART1(void);
unsigned char *Float2Ascii (float x, unsigned char *chaine,char precision) ;
void CRLF1(void) ;
void Read_Msg64_Eeprom( unsigned char * T,int depuis);

void SPI_Write_To_8x7219(Byte char adr, Byte d1, Byte d2,Byte d3, Byte d4, Byte d5,Byte d6, Byte d7,Byte d8);
void Clear_Matrices(void) ;
void Affiche_Char(Byte c, unsigned int v);
void Init_Module_Max7129_8x8(void);
void Affiche_Text_Matrice(Byte *p1, unsigned int V1);
void Affiche_CText_Matrice(const Byte *p2, unsigned int V2);
void SPI_WRITE_Byte( Byte x);

#define With_I2C2

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 7/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

#define DS1307 0xD0

#include "Fonte_Ascii_8x8.h"

#define REG_DECODE 0x09 // "decode mode" register


#define REG_INTENSITY 0x0A // "intensity" register
#define REG_SCAN_LIMIT 0x0B // "scan limit" register
#define REG_SHUTDOWN 0x0C // "shutdown" register
#define REG_DISPLAY_TEST 0x0F // "display test" register
#define INTENSITY_MIN 0x00 // minimum display intensity 1/32
#define INTENSITY_MAX 0x0F // maximum display intensity 31/32
#define INTENSITY_MOY 0x07 // moyenne 15/32

void Interrupts() iv 0x0008 ics ICS_AUTO


{
if ( (RC1IE_bit==1) && ( RC1IF_bit==1))
{
//TXREG1='$';
// traitement separe des erreurs de COM
// c1 = UART1_Read();
c1=RCREG1;
if ([Link]==1) // voir parag 16.1.26 p273
{
[Link] = 0 ;
c1 = RCREG1;
[Link] = 1 ;
CptErr++;

}
if([Link]==1 )
{
[Link] = 0 ;
[Link]= 1 ;
CptErr++;
c1 = RCREG1;
}
if ((c1==CR) || (i1 > MAXLEN_BUFFER1-2))
{
Flag_Buffer1=1;
if (i1 > MAXLEN_BUFFER1-2) Flag_Buffer1=2;
PIE1.RC1IE=0 ; //interdit IT Reception UART
buffer1[i1]=0;
Index1=i1;
i1=0;
c1=0;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 8/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

}
else
{

buffer1[i1]=c1;
Index1=i1;
i1++;

}
}
// comptage depassement Timer0
// if ((TMR0IE_bit) && (TMR0IF_bit) )
// { //TXREG1='*';
// OverFlow_Timer0++;
// TMR0IF_bit = 0;
// }

// ----- timer 1 ----------------


if ( (TMR1IE_bit==1) && ( TMR1IF_bit==1))
{ // Test "Peripheral Interrupt Request Register 1" for Timer1 Flag
Cpt1++;

if (Cpt1 >=Max_Timer1) // x100 ms @8MHz


{
TMR1IE_bit=0; // stop comptage timer1
TMR1ON_bit=0;
Flag_Timer1=1;
}
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IF_bit=0;
}

void Init_Module_Max7129_8x8()
{
SPI_Write_To_8x7219(REG_DISPLAY_TEST, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x00, 0x00); // pas de test - no test
SPI_Write_To_8x7219(REG_DECODE, 0x00, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x00); //pas de decodage - no decode
SPI_Write_To_8x7219(REG_INTENSITY,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01); //intensité - intensity minima
//intensité - intensity minima
//scan limit registre digit 0 à 7 .. les colonnes de la matrice
SPI_Write_To_8x7219(REG_SCAN_LIMIT , 0x07,0x07, 0x07,0x07,0x07,0x07,0x07,0x07);
SPI_Write_To_8x7219(REG_SHUTDOWN, 0x01, 0x01, 0x01, 0x01,0x01, 0x01, 0x01, 0x01); // normal operation
Delay_ms(2);
Clear_Matrices() ;
Delay_ms(10);

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 9/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

void SPI_Write_To_8x7219(Byte adr, Byte d1, Byte d2,Byte d3, Byte d4, Byte d5,Byte d6,Byte d7,Byte d8)
{ SPI_CS = 0;
Delay_us(15);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d1);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d2);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d3);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d4);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d5);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d6);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d7);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d8);
Delay_us(10);
SPI_CS = 1;
}

void SPI_Write_To_6x7219(Byte adr, Byte d1, Byte d2,Byte d3, Byte d4, Byte d5,Byte d6,Byte d7,Byte d8)
{ SPI_CS = 0;
Delay_us(15);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d1);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d2);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d3);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d4);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d5);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d6);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d7);
SPI_WRITE_Byte(adr); SPI_WRITE_Byte(d8);
Delay_us(10);
SPI_CS = 1;
}

void SPI_WRITE_Byte(Byte x)
{
int i;
Byte c;
c=x; Delay_us(4);
// SPI_DOUT=0;
for (i=0;i<8;i++)
{
if ((c & 0x80)==0x80)
SPI_DOUT=1;
else
SPI_DOUT=0;
Delay_us(8);
c=c<<1;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 10/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

SPI_CLOCK=1;
Delay_us(8);
SPI_CLOCK=0;
Delay_us(8);
}

void Clear_Matrices()
{
Byte i;
for (i = 0; i < 8; i++)
{
SPI_Write_To_6x7219(i+1,0,0,0,0,0,0,0,0); //8 afficheurs,0,0 ); // efface 8 afficheurs
}
}

void Affiche_Char(Byte c, unsigned int v)


{
unsigned int i,j,k;
char n;
k=c * 8;
n=0;
Aff_buffer[0]=font_8x8[c];
for (j = 0; j < 8; j++)
{
for (i = 63; i > 0; i--)
{
Aff_buffer[i] = Aff_buffer[i-1];
}
Aff_buffer[0] =font_8x8[j + k];
n = 0;
for (i = 8; i > 0; i--)
{
SPI_Write_To_6x7219(i, Aff_buffer[n], Aff_buffer[n+8],Aff_buffer[n+16],Aff_buffer[n+24], Aff_buffer[n+32],
Aff_buffer[n+40],Aff_buffer[n+48],Aff_buffer[n+56]);
n++;
}
for(i=0;i<v;i++) Delay_ms(1);
}
}

void Affiche_Text_Matrice(Byte *p1, unsigned int V1)

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 11/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

{
Byte c1;
int k1;
k1=strlen(p1);
while (*(p1)>0)
{
SPI_CS=0;
c1=*(p1);
Affiche_Char(c1, V1);
p1++;
SPI_CS=1;
k1--;
}

SPI_CS=1;
}

void Affiche_CText_Matrice(const Byte *p2, unsigned int V2)


{
while (*(p2)>0)
{
SPI_CS=0;
Affiche_Char(*(p2),V2);
p2++;
SPI_CS=1;
}

void Write_DS1307(unsigned char addresse, unsigned char dd)


{
int i;
I2C2_Start();
I2C2_Wr(DS1307);
I2C2_Wr(addresse);
I2C2_Wr(dd);
I2C2_Stop();
}

unsigned char Read_DS1307(unsigned char address)


{ unsigned char dummy;
I2C2_Start();
I2C2_Wr(DS1307);
I2C2_Wr(address);
I2C2_Repeated_Start();
I2C2_Wr(DS1307+1); // b0 is read
dummy=I2C2_Rd(0); // Read with NACK.

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 12/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

I2C2_Stop();
return(dummy);
}

void Start_DS1307()
{
if (DS1307_Started) return ;
dummy = Read_DS1307(0) & ~0x80; // CH = 0 - start.
Write_DS1307(0,dummy);
DS1307_Started = 1;
}

void Stop_DS1307()
{
dummy = Read_DS1307(0) | 0x80; // CH = 1 - stop.
Write_DS1307(0,dummy);
DS1307_Started = 0;
}

void Init_DS1307()
{
if (Read_DS1307(0x3E)==0x20) return; // adresse fin de RAM-1
Start_DS1307(); // demarre oscillator
// mode 24H
Write_DS1307(2,Read_DS1307(2) & ~(1<<6) ); // RAZ le bit 6 pour passer en mode 24 heures.
Write_DS1307(0,0x00 & 0x7F); // secondes
Write_DS1307(1,0x05); // minutes 0-59
Write_DS1307(2,0x20 & ~(1<<6) ); // mode 24 hour + heures
Write_DS1307(3,0x00); // jour de la semaine 1-7
Write_DS1307(4,0x24); // date 1 à 31
Write_DS1307(5,0x12); // mois 1-12
Write_DS1307(6,0x19); // Annee 0-99
Write_DS1307(7,0x10); // Sortie SQW 1Hz
Write_DS1307(0x3E,0x20); // drapeau RTC initalisée

void Write_Date_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *month, char *year)
{
I2C2_Start(); // start signal
I2C2_Wr(DS1307); // addresse DS1307
I2C2_Wr(0); // start from REG 0
I2C2_Wr(0x80+ sec); // write $80 to REG 0. (pause counter + 0 sec)
I2C2_Wr(min); // write Minutes to REG 1
I2C2_Wr(hr); // write Heures (mode 24H) to REG 2
I2C2_Wr(week_day); // write jour to REG 3

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 13/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

I2C2_Wr(day); // write 27 date to REG 4


I2C2_Wr(month); // write 12 Dec to REG 5
I2C2_Wr(year); // write 16 year to REG 6
// I2C2_Repeated_Start();
I2C2_Stop(); // issue stop signal
I2C2_Start(); // issue start signal
Delay_ms(10);
I2C2_Wr(DS1307); // address DS1307
I2C2_Wr(0); // start from word at address 0
I2C2_Wr(0); // write 0 to REG0 (enable counting + 0 sec)
I2C2_Stop(); // issue stop signal
}

void Read_Date_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *month, char *year)
{
I2C2_Start();
I2C2_Wr(DS1307);
I2C2_Wr(0);
I2C2_Repeated_Start();
I2C2_Wr(DS1307+1);
*sec =I2C2_Rd(1);
*min =I2C2_Rd(1);
*hr =I2C2_Rd(1);
*week_day =I2C2_Rd(1);
*day =I2C2_Rd(1);
*month=I2C2_Rd(1);
*year =I2C2_Rd(0);
I2C2_Stop();
}

void Transform_Time(char *sec, char *min, char *hr, char *week_day, char *day, char *month, char *year)
{
*sec = ((*sec & 0x70) >> 4)*10 + (*sec & 0x0F);
*min = ((*min & 0xF0) >> 4)*10 + (*min & 0x0F);
*hr = ((*hr & 0x30) >> 4)*10 + (*hr & 0x0F);
*week_day =(*week_day & 0x07);
*day = ((*day & 0xF0) >> 4)*10 + (*day & 0x0F);
*month = ((*month& 0x10) >> 4)*10 + (*month& 0x0F);
*year = ((*year & 0xF0)>>4)*10+(*year & 0x0F);
}

void Prepare_Display_Time(char sec, char min, char hr, char week_day, char day, char monthn, char year)
{
Date[0]=(day / 10) + 48;
Date[1]= (day % 10) + 48;
Date[2]='/';
Date[3]=(month/ 10) + 48;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 14/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

Date[4]=(month% 10) + 48;


Date[5]='/';
Date[6]='2';
Date[7]='0';
Date[8]=(year / 10) + 48;
Date[9]=(year % 10) + 48;
Date[10]=0;

Time[0]=(hr / 10) + 48;


Time[1]=(hr % 10) + 48;
Time[2]=':';
Time[3]=(min / 10) + 48;
Time[4]=(min % 10) + 48;
Time[5]=':';
Time[6]=(sec / 10) + 48;
Time[7]=(sec % 10) + 48;
Time[8]=0;
}

void Wait_100mS()
{
Delay_ms(100);
}

void Read_Msg64_Eeprom(unsigned char *T, int debut)


{ int i1 ,i;
i1=0;
do
{
i = EEPROM_Read(i1+debut);
if ( i==0) break;
if ( i1>63) break;
//UART1_Write(i);
*(T+i1)=i;
Delay_ms(1);
i1++;
}
while (i!=0) ;
*(T+i1-1)=0;
}

void Raz_Buffer1()
{
// nettoye le buffer
for(Index1=0;Index1<MAXLEN_BUFFER1-1;Index1++) buffer1[Index1]=0;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 15/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

i1=0;
Index1=0;
c1=0;
Flag_Buffer1 =0;
[Link]=0 ;
[Link]=1 ;
PEIE_bit=1;
c1=RC1REG;
RC1IE_bit = 1 ;
p1=0;
}

void Stop_Timer0(void)
{
Flag_Timer0=0;
TMR0IF_bit=0;
TMR0IE_bit=0;
Count0=0;
}

void Send_Cde_display_response(const char* Cde)


{ char *p2;
Raz_Buffer1();
p2=0;
// UART3_Write_CText(Cde);
strConstRamCpy(txt,Cde);
k=strlen(txt);
*(txt-1)=0;
UART1_Write_Text(txt);
Init_Timer0() ;
while((p2==0) && (Flag_Timer0==0) )
{
Delay_ms(100);
p2=strstr(buffer1,"OK");
}
Stop_Timer0();
if(p2>0) Pas++;
Delay_ms(26); // duree maxi de reponse Version
}

void HC06_J_Init()
{ int N; char ADDR[32];
N=0;
CRLF1();

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 16/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

strConstRamCpy(CRam1,"OK");
Send_Cde_display_response("AT\r\n");
Send_Cde_display_response("AT+VERSION\r\n");
Send_Cde_display_response("AT+PIN1234\r\n");
Send_Cde_display_response("AT+NAMEHC06_8701B\r\n");
}

// --- Copie le texte depuis FLASH ROM vers RAM


void strConstRamCpy(unsigned char *dest, const code char *source)
{
while (*source)*dest++ = *source++ ;
*dest = 0 ; // terminateur
}

void CRLF1()
{
UART1_Write(CR);
UART1_Write(LF);
}

void UART1_Write_CText(const char *txt)


{
while (*txt)
UART1_Write(*txt++);
Delay_us(5);
}

void Float2Ascii (float x, unsigned char *str,char precision)


{
// converts a floating point number to an ascii string
// version limitée à 5 decimales maximum le 21-01-2019
// old version limitée à 6 decimales maximum
// x is stored into str, which should be at least 30 chars long
int ie, i, k, ndig;
double y;
if (precision>=5) precision=5; else precision++;
ndig = precision;
ie = 0;
// if x negative, write minus and reverse
if ( x < 0.00000)
{
*str++ = '-';
x = -x;
}
// put x in range 1 <= x < 10
if (x > 0.000000) while (x < 1.000000)

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 17/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

{
x *= 10.000; // a la place de =*
ie--;
}
while (x >= 10.0000)
{
x = x/10.0000;
ie++;
}
// in f format, number of digits is related to size
ndig += ie; // a la place de =+
//round. x is between 1 and 10 and ndig will be printed to
// right of decimal point so rounding is ...
for (y = i = 1; i < ndig; i++)
y = y/10.0000;
x += y/2.0000;
if (x >= 10.0000) {x = 1.0000; ie++;}
if (ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig;
for (i = -1; i > ie; i--) *str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == ie ) *str++ = '.';
x -= (y=k);
x *= 10.0000;
}
*str = '\0';
}

void Init_Hardware()
{
PORTC = 0x00; // RC0..RC5,RC7 = input RC6=Output
ANSELC=0;
TRISC = 0xFF; //
TRISC.TRISC7 = 1; // RX - UART1
TRISC.TRISC6 = 0; // TX - UART1

PORTC.B0=1;
SPI_CS_Dir=0;
SPI_CS=1;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 18/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

PORTA = 0b00111111;
ANSELA=0;
TRISA = 0b00011110 ; // PORTA is RA0,1= analog input RA2=anaolg -Vref, RA3, RA4=Input RA5,6=Digital output
Debug_Time_Dir=1;
Led_Rouge_Dir=0;
Led_Rouge=0;
CCP5CON=0;

PORTB = 0xFF;
TRISB = 0x83; // B0,B1 as input ATTENTION B7 B6 for ICSP Pickit3
ANSELB=0;
PORTD=0;
ANSELD=0;
TRISD=0xFF;
TRISD.TRISD0 = 0; // SCL I2C2
TRISD.TRISD1 = 0; // SDA I2C2
TRISD.TRISD6 = 0; // TX UART2
TRISC.TRISD7 = 1; // RX UART2

SLRCON=0; // standard rate for PORTA,B,C,D,E


}

void Init_Timer0(void)
{
// init en compteur sur entree RA4
T08BIT_bit=0; // mode 16 bits
T0CS_bit=1; // mode comptage sur pin T0CKI= RA4
T0SE_bit=1; // front edge
PSA_bit=1; // 1= Not use of prescaler => 1/1 , because, if used prescaler minimum is 1/2
T0PS2_bit=0; // prescaler 1/2
T0PS1_bit=0;
T0PS0_bit=0;
TMR0H = 0;
TMR0L = 0;
TMR0IP_bit=1; // high priority
TMR0IF_bit=0;
TMR0IE_bit=1;
OverFlow_Timer0=0;
TMR0ON_bit=1;
}

void Arme_Timer1(void)

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 19/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

{
// 100mS * Max_Timer1
TMR1H = 0x3C;
TMR1L = 0xB0;
Cpt1=0;
Flag_Timer1=0;
TMR1ON_bit=1; // Timer0 ON
TMR1IF_bit = 0;
TMR1IE_bit= 1;
}

void Init_Timer1(void)
{
//Timer1 FOSC=8MHz
//Prescaler 1:4; TMR1 Preload = 15536; Actual Interrupt Time : 100 ms
T1CON = 0x21;
// TMR1CS1_bit=0; // FOSC/4
// TMR1CS0_bit=0;
T1RD16_bit=1;
// T1CKPS1_bit=1; //Prescaler 1:8
// T1CKPS0_bit=1;
TMR1H = 0x3C;
TMR1L = 0xB0;
TMR1IF_bit = 0;
TMR1IP_bit=1; // high level interrupt
Cpt1=0;
Flag_Timer1=0;
TMR1ON_bit=0;
TMR1IE_bit =0;
}

void MAJ_RTC()
{ int m,l,j,i;
m=2; // passe par dessus "U;"
j=0;

CRLF1();
l=strlen(buffer1);
//WordToStr(l,CRam1);
// UART1_Write_Text(CRam1);
// CRLF1();
// U;28;12;16;03;21;59#
UART1_Write_CText("\n\rMise a l'heure RTC :");
UART1_Write_Text(buffer1);

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 20/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

// CRLF1();
for (i=2;i<l;i++)
{
if(buffer1[i]==';')
{
buffer1[i]=0;
DateTime[j]=atoi(buffer1+i-2);
j++;
}
}// for i
// ne pas oublier le dernier!
buffer1[19]=0; // elimine le # en fin de chaine
DateTime[j]=(buffer1[17]-48)*10 + buffer1[18]-48;
day=Dec2Bcd(DateTime[0]);
month=Dec2Bcd(DateTime[1]);
year=Dec2Bcd(DateTime[2]);
week_day=Dec2Bcd(DateTime[3]); // jour de la semaine sur 1 seul digit
hr=Dec2Bcd(DateTime[4]);
min1=Dec2Bcd(DateTime[5]);
sec=0;
// CRLF1();
/* pour debugging
UART1_Write_CText("\r\nSaisie : \r\n");
for (i=0;i<6;i++)
{
ByteToStr(DateTime[i],CRam1);
UART1_Write_Text(CRam1);
CRLF1();
}

*/

sec= 0;
CRLF1();
Stop_DS1307();
Write_Date_Time(sec,min1,hr,week_day,day,month,year);
UART1_Write_CText("\n\r RTC Updated \r\n");
Start_DS1307();

void DS18B20_Build_value(unsigned int temp2write)


{
int jj;
const unsigned int RES_SHIFT = TEMP_RESOLUTION - 8;
unsigned char temp_whole;

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 21/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

char Signe=0;
unsigned int temp_fraction;
// Check if temperature is negative
// Check if temperature is negative
if (temp2write & 0x8000) {
Signe=1 ;
CRam1[0] = '-';
temp2write = ~temp2write + 1;
}
else
{
Signe=0;
CRam1[0] = ' ';
}
// Extract temp_whole
temp_whole = temp2write >> RES_SHIFT ;
// Convert temp_whole to characters
CRam1[1] = (temp_whole/10)%10 + 48; // Extract tens digit
if (CRam1[1]=='0')CRam1[1]=' ';
CRam1[2] = temp_whole%10 + 48; // Extract ones digit
// Extract temp_fraction and convert it to unsigned int
temp_fraction = temp2write << (4-RES_SHIFT);
temp_fraction &= 0x000F;
temp_fraction *= 625;
CRam1[3]='.';
// Convert temp_fraction to characters
CRam1[4] = temp_fraction/1000 + 48; // Extract thousands digit
CRam1[5] = (temp_fraction/100)%10 + 48; // Extract hundreds digit
// CRam1[6] = (temp_fraction/10)%10 + 48; // Extract tens digit
CRam1[6]=0;//
//CRam1[7]= temp_fraction%10 + 48; // Extract ones digit
CRam1[7]=0;//
CRam1[8]=0;
Ltrim(CRam1+1);
DS18B20_Temp1= ( temp_whole *1000) +temp_fraction ;
}

void Wait_250uS(void)
{
Delay_us(250);
}

void main()
{

#ifdef FOSC_INTERNE

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 22/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

// 1MHz par defaut


// OSCCON = 0b01110010 ; //0x72 ; //Oscillateur à 16Mhz
// OSCCON = 0b01100010 ; //0x62 ; //Oscillateur à 8Mhz
OSCTUNE=0;
//OSCCON = 0b01100100 ; //0x60; //Oscillateur à 8Mhz AVEC PLL
OSCCON = 0b01110010 ; //0x72 ; //Oscillateur à 16Mhz
[Link]=0 ; // 8MHz x pll =32Mhz
OSCCON2=0;
while ([Link]==0); // wait stable oscillator
#else
// Q=20Mhz
#endif

Init_Hardware() ;
SPI_CS=1;
Delay_ms(1500);

Speed=100;
Max_Timer1=8;
Led_Rouge=0;
for (i=0;i<MAXLEN2;i++)
{
TEXTE[i]=0;
TEXTE2[i]=0;
}
txt=&TEXTE[0];
txt2=&TEXTE2[0];

UART1_Init(19200);
Delay_ms(100);
UART1_Write(CLS); // Erase screen terminal :it is an option on Vbray Terminal!
Delay_ms(500);

CRLF1();
// presentation sur UART1
UART1_Write_CText (" Presentation : \r\n");
for(i=0;i<8;i++)
{
UART1_Write_CText(Messages[i]);
}
Delay_ms(1000);
CRLF1();

UART1_Write_CText("Test reg. DS18B20\r\n");


Wait_100mS();

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 23/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

j=0;
Ow_Reset(&PORTA, 0); // Onewire reset signal
Wait_250uS();
Ow_Write(&PORTA, 0, 0x33); // Read ROM (if only one device)
Wait_250uS();
c1=Ow_Read(&PORTA, 0); // 123456789012345678901234567890123456789012345678
Wait_250uS();
UART1_Write_CText("Family Code : ");
// UART3_Write_CText("Family Code : ");
*(CRam1)=0;
ByteToHex(c1,CRam1);
UART1_Write_Text(CRam1);
UART1_Write_CText(" ID1= ");
for (i=0;i<6;i++)
{
c1= Ow_Read(&PORTA, 0);
Wait_250uS();
ID1[i]=c1;
*(CRam1)=0;
ByteToHex(c1,CRam1);
UART1_Write_Text(CRam1);
}
UART1_Write_CText(" CRC= ");
c1= Ow_Read(&PORTA, 0); // CRC
*(CRam1)=0;
ByteToHex(c1,CRam1);
UART1_Write_Text(CRam1);
CRLF1();

clk = Clock_kHz();
strConstRamCpy(txt,"\r\nClock initiale in = ... Khz \r\n");
WordToStr(clk,CRam1);
memcpy(txt+ 23,CRam1,5);
UART1_Write_Text(txt);

// ========== Test zone =========================

// =================================

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 24/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

I2C2_Init(400000);
UART1_Write_CText("Init I2C2 (RD0=SCL2) et RD1=SDA2 )400Khz pour RTC DS1307 \r\n");
DS1307_Started=0;
Init_DS1307();
Start_DS1307();
Delay_ms(500);
Prepare_Display_Time( sec, min1,hr, week_day, day, month, year );
UART1_Write_CText("DS1307 Date :");
UART1_Write_Text(Date);
UART1_Write_CText(" Time: ");
UART1_Write_Text(Time);
CRLF1();

// IPEN_bit=1;
IPR1.RC1IP=1;
PIR1.RC1IE=1;
[Link]=1;
// [Link] = 1; // enable priority levels , car TMR1 => low interrupt
PEIE_bit = 1; // Enable Peripheral interrupt
GIE_bit = 1; // Enable Global interrupt

UART1_Write_CText("Init et test interrupt Timer1 20 x 100 msec soit 2sec \r\n" );


Max_Timer1=20;
Init_Timer1();
Arme_Timer1();
TXREG1='$';
CRLF1();
while(Flag_Timer1==0);
TXREG1='#';
CRLF1();
k=0;

UART1_Write_CText("Waiting 5 sec ..\r\n");


Raz_Buffer1() ;
Max_Timer1=50; // 60x100mS => 6sec
Init_Timer1();
Arme_Timer1();
do
{
if (Flag_Buffer1==1)
{
UART1_Write_CText("Recu :");
UART1_Write_Text(buffer1);
CRLF1();
}
}

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 25/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

while ( (Flag_Timer1==0) && (Flag_Buffer1==0));


if (Flag_Timer1==1) UART1_Write_CText("Time Out \r\n");
Raz_Buffer1() ;

// ========================================= */

UART1_Write_CText("Soft SPI RC3=Clk ,RC5=Dout RC0=CS -> MAx7219:\r\n" ) ;


Soft_SPI_Init();
SPI_CS=1;

Init_Module_Max7129_8x8();
UART1_Write_CText("Clear Matrice 6x 8x8\r\n" ) ;
Clear_Matrices() ;
Delay_ms(100);
Clear_Matrices() ;

UART1_Write_CText("Display <0123456789AB> sur 8 matrices 8x8 Leds \r\n");


Init_Module_Max7129_8x8();
Clear_Matrices() ;
SPI_Write_To_6x7219(REG_INTENSITY,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01); //,0x01,0x01); //intensité - intensity minima
Clear_Matrices() ;
Affiche_CText_Matrice("0123456789AB", 7);
Delay_ms(1000);

Max_Timer1=10;
txt=&TEXTE[0];
[Link]=1 ; // inactif par defaut
Cpt=0;
Speed=20; // par defaut

while(1)
{
GIE_bit=0;
Init_Module_Max7129_8x8();
Clear_Matrices() ;
Affiche_CText_Matrice(" ",Speed);

Raz_Buffer1();
GIE_bit=1;
Delay_ms(1000);

txt2=&TEXTE2[0];
txt=&TEXTE[0];
Read_Date_Time(&sec,&min1,&hr,&week_day,&day,&month,&year); // read time from RTC(DS1307)
Transform_Time(&sec,&min1,&hr,&week_day,&day,&month,&year); // format date and time
Prepare_Display_Time( sec, min1,hr, week_day, day, month, year );

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 26/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

Ow_Reset(&PORTA, 0); // Onewire reset signal


Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0x44); // Issue command CONVERT_T
Wait_250uS();
Ow_Reset(&PORTA, 0);
Ow_Write(&PORTA, 0, 0xCC); // Issue command SKIP_ROM
Ow_Write(&PORTA, 0, 0xBE); // Issue command READ_SCRATCHPAD for only one sensor
//Byte 0 and byte 1 of the scratchpad contain the LSB and the MSB of the temperature register
tempL = Ow_Read(&PORTA, 0);
temp = (Ow_Read(&PORTA, 0) << 8) + tempL;
DS18B20_Build_value(temp);
//Ltrim(CRam1);
k=strlen(CRam1);
strConstRamCpy(CRam1+k,"°C ");
UART1_Write_Text(CRam1); CRLF1();
k=strlen(CRam1);
for(i=0;i<k;i++)
{
if(*(CRam1+i)=='°') *(CRam1+i)=126;
}
Clear_Matrices() ;
Affiche_CText_Matrice(" ", 1);
Affiche_Text_Matrice(CRam1, Speed);
i=5; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);
Delay_ms(600);
i=1; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);

txt=&TEXTE[0];
strcpy(txt,Date);
k=strlen(txt);
strcat(txt+k," ");
k=strlen(txt);
strcat(txt+k,Time);

Affiche_Text_Matrice(txt, Speed);
i=5; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);
Delay_ms(600);
i=1; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);

//3em affichage
if (strlen(txt2)>7)
{

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 27/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

Affiche_Text_Matrice(txt2, Speed);
i=5; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);
Delay_ms(400);
i=1; SPI_Write_To_6x7219(REG_INTENSITY,i,i,i,i,i,i,i,i);
}

UART1_Write_CText("Compteur= ");
ByteToStr(Cpt,CRam1);
UART1_Write_Text(CRam1) ;
CRLF1();

Cpt++;

if (Flag_Buffer1==1)
{
// UART1_Write_Text(buffer1);CRLF1();
p1= strstr(buffer1,"Msg="); // p pointer result
if (p1>0)
{
k=strlen(buffer1);
if ((k>6) && (k<122))
{ txt2=&TEXTE2[0];
UART1_Write_CText("\r\nhello, i get your Msg!");
UART1_Write_Text(buffer1+4);CRLF1();
strcpy(txt2,buffer1+5);
}
else *(txt2)=0;
p1=0;
} //p1
p1= strstr(buffer1,"TEMP_ON"); // p pointer result
if (p1>0)
{
[Link]=1;
k=strlen(buffer1);
UART1_Write_CText("\r\nOK, Temper is ON!\r\n");
} //p1
p1= strstr(buffer1,"TEMP_OFF"); // p pointer result
if (p1>0)
{
[Link]=0;
UART1_Write_CText("\r\nOK, Temper is OFF!\r\nRetour au display txt \r\n");
} //p1
p1= strstr(buffer1,"Speed="); // p pointer result
if (p1>0)
{

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 28/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

#ifdef DEBUGGING
CRLF1();UART1_Write_Text(buffer1);CRLF1();
#endif
k=strlen(buffer1);
// test si tous les caracteres sont des chiffres (digit)
if(k>6)
{
m=0;
for (i=0;i<(k-6);i++)
{
if ((*(buffer1+6+i)>='0')&&(*(buffer1+6+i)<='9')) m++;
}
if (m==(k-6))
{
n= atoi(buffer1+6);
#ifdef DEBUGGING
UART1_Write_CText("\r\n n= ");
WordToStr(n,CRam1);
UART1_Write_Text(CRam1);
UART1_Write_CText(" m= ");
WordToStr(m,CRam1);
UART1_Write_Text(CRam1);CRLF1();
#endif
if ((n>1)&&(n<255)) Speed=n;
UART1_Write_CText("\r\nChange Speed To ");
WordToStr(Speed,CRam1);
UART1_Write_Text(CRam1);CRLF1();
}
}
p1=0;
} //p1
p1= strstr(buffer1,"Eeprom="); // p pointer result
if (p1>0)
{
k=strlen(buffer1);
if((k>7)&&(k<10))
{
m=0;
for (i=0;i<(k-7);i++)
{
if ((*(buffer1+7+i)>='0')&&(*(buffer1+7+i)<='9')) m++;
}
if (m==(k-7))
{
n= atoi(buffer1+7);
// #ifdef DEBUGGING
UART1_Write_CText("\r\n m= ");

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 29/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

WordToStr(n,CRam1);
UART1_Write_Text(CRam1);UART1_Write(TAB);
// #endif
if ((n>=0)&&(n<16))
{
k=n<<6;
// #ifdef DEBUGGING
UART1_Write_CText(" Eeprom Msg adresse ");
WordToHex(k,CRam1);
UART1_Write_Text(CRam1);CRLF1();
// #endif
Read_Msg64_Eeprom(txt,k);
}
}
}
p1=0;
} //p1

if ((buffer1[0]=='U') && (buffer1[19]=='#'))


{
// attendu : U;21;12;18;06;19;27#
// UART1_Write_CText("RTC MAJ au format : U;04;06;14;04;19;59#\r\n");
MAJ_RTC();
// Date[12]; // dd/mm/20yy\0
// Time[9]; // hh:mn:ss\0
Read_Date_Time(&sec,&min1,&hr,&week_day,&day,&month,&year); // read time from RTC(DS1307)
Transform_Time(&sec,&min1,&hr,&week_day,&day,&month,&year); // format date and time
Prepare_Display_Time( sec, min1,hr, week_day, day, month, year );
UART1_Write_CText("New DS1307 Date :");
UART1_Write_Text(Date);
UART1_Write_CText(" New Time: ");
UART1_Write_Text(Time);
CRLF1();
*(buffer1)=0 ;
p1=0;
}
p1= strstr(buffer1,"Demo"); // p pointer result
if (p1>0)
{
UART1_Write_CText("Affiche Messages 0 à 15 stockes en EEPROM du PIC18F \r\n" ) ;
for (i=0;i<15;i++)
{
k=i<<6;
Read_Msg64_Eeprom(txt,k);
UART1_Write_CText("Eeprom # ");
WordToHex(k,CRam1);UART1_Write_Text(CRam1);UART1_Write(TAB);
UART1_Write_Text(txt); CRLF1();

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 30/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

Affiche_Text_Matrice(txt, Speed);
Delay_ms(1000);
}
p1=0;
}//p1
p1= strstr(buffer1,"Reset"); // p pointer result
if (p1>0)
{
UART1_Write_CText("Reset Afficheurs Matrice 8x8 \r\n" ) ;
Init_Module_Max7129_8x8();
UART1_Write_CText("Clear Matrice 6x 8x8\r\n" ) ;
Clear_Matrices() ;
Delay_ms(1000);
p1=0;
}//p1
p1= strstr(buffer1,"Help"); // p pointer result
if (p1>0)
{

UART1_Write_CText(
"<Msg=> L maxi=122 cars\r\n"
"<Reset> Re-Init afficheurs MAX7219\r\n"
"<TEMP_ON> Affiche la Temp. DS18B20\r\n"
"<TEMP_OFF> Enleve Affichage DS18B20\r\n"
"<Speed=> Vitesse defilement :valeur de 2 à 250\r\n"
"<Eeprom=> Message en eeprom avec indice 1 à 15\r\n"
"<U;04;06;14;04;19;59#> Maj de la RTC\r\n"
"<Demo> affiche tous les messages en EEPROM PIC\r\n" );
CRLF1();
p1=0;
}
} // flag
if(Flag_Buffer1==2) UART1_Write_CText("Debordement Buffer1 \r\n");
} //while1
}

/*

Presentation :
Mikroc 7.2.0 18F46K22
Directory : C:_MikroC_MesProjets_MikroC_18F46K22_8_Matrix8x8
Projet : 18F46K22_MAX7219_8x_Mat_8x8_SPI1_Softw_LM335_DS1307_I2C2.mcppi
Source : _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_special_NOEL__190126.c
8 Modules Matrice 8x8 avec MAX7129 + capteur OWS DS18B20
Saisir un nouveau Msg avec le terminal via <Msg=xxxx>
Mode Temperature avec <TEMP_ON> ou <TEMP_OFF>
Messages en EEPROM avec cde : <EEPROM=0> .. à 15

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 31/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

Test reg. DS18B20


Family Code : 28 ID1= FF4715811603 CRC= 24

Clock initiale in = 16000 Khz


Init I2C2 (RD0=SCL2) et RD1=SDA2 )400Khz pour RTC DS1307
DS1307 Date :26/01/2019 Time: [Link]
Init et test interrupt Timer1 20 x 100 msec soit 2sec
$
#
Waiting 5 sec ..
Time Out
Soft SPI RC3=Clk ,RC5=Dout RC0=CS -> MAx7219:
Clear Matrice 6x 8x8
Display <0123456789AB> sur 8 matrices 8x8 Leds
15.18°C
Compteur= 0
15.18°C
Compteur= 1
15.18°C
Compteur= 2
15.18°C
Compteur= 3

Mise a l'heure RTC :U;26;01;19;05;11;30#

RTC Updated
New DS1307 Date :26/01/2019 New Time: [Link]
15.18°C

0 1 [Link] -MSF -DBG -pP18F46K22 -C -DL -O11111114 -fo16 -


EH"C:\_MikroC\_MesProjets_MikroC\_18F46K22_8_Matrix8x8\18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20_eeprom.ihex" -
N"C:\_MikroC\_MesProjets_MikroC\_18F46K22_8_Matrix8x8\18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20.mcppi" -SP"C:\_MikroC\mikroC PRO for
PIC\Defs\" -SP"C:\_MikroC\mikroC PRO for PIC\uses\P18\" -SP"C:\_MikroC\_MesProjets_MikroC\_18F46K22_8_Matrix8x8\" -SP"C:\_MikroC\mikroC PRO for
PIC\Tools\" -SP"C:\_MikroC\mikroC PRO for PIC\" -IP"C:\_MikroC\mikroC PRO for PIC\uses\P18\" -
IP"C:\_MikroC\_MesProjets_MikroC\_18F46K22_8_Matrix8x8\" "_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c"
"__Lib_Math.mcl" "__Lib_MathDouble.mcl" "__Lib_System.mcl" "__Lib_Delays.mcl" "__Lib_CType.mcl" "__Lib_CString.mcl" "__Lib_CStdlib.mcl"
"__Lib_Conversions.mcl" "__Lib_Time.mcl" "__Lib_OneWire.mcl" "__Lib_SoftSPI.mcl" "__Lib_ADC_K22_B.mcl" "__Lib_EEPROM_1024.mcl"
"__Lib_I2C_c34d01.mcl" "__Lib_UART_c67d67.mcl"
0 1139 Available RAM: 3875 [bytes], Available ROM: 65536 [bytes]
0 122 Compilation Started _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
0 1004 interrupt handler (Interrupts at 0x0008) _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
547 1163 Variable 'i' has been declared, but not used _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
624 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
625 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
626 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 32/33
17/10/2019 [Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c

627 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c


628 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
629 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
630 1506 Implicit conversion of pointer to int _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
765 1163 Variable 'ADDR' has been declared, but not used _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
995 1508 Implicit conversion of int to ptr _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
1004 1163 Variable 'jj' has been declared, but not used _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
1079 1509 Generated baud rate is 19231 bps (error = 0.16 percent) _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
1438 123 Compiled Successfully _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
517 1164 Variable 'c1' has been eliminated by optimizer _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
518 1164 Variable 'k1' has been eliminated by optimizer _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
765 1164 Variable 'N' has been eliminated by optimizer _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
948 1164 Variable 'm' has been eliminated by optimizer _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
1007 1164 Variable 'Signe' has been eliminated by optimizer _18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190124.c
0 127 All files Compiled in 156 ms
0 1144 Used RAM (bytes): 1272 (33%) Free RAM (bytes): 2603 (67%) Used RAM (bytes): 1272 (33%) Free RAM (bytes): 2603 (67%)
0 1144 Used ROM (bytes): 14505 (22%) Free ROM (bytes): 51031 (78%) Used ROM (bytes): 14505 (22%) Free ROM (bytes): 51031 (78%)
0 125 Project Linked Successfully 18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20.mcppi
0 128 Linked in 62 ms
0 129 Project '18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20.mcppi' completed: 250 ms
0 103 Finished successfully: 24 janv. 2019, [Link] 18F46K22_MAX7219_8x_Mat_8x8_I2C2_DS1307_OWS_DS18B20.mcppi

*/

[Link]/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 33/33

Vous aimerez peut-être aussi