// temper
// #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 FOSC_INTERNE
#define FOSC 16.0
#define BAUD 19200 // UART1
#define Langage Mikroc V 7.10
#define With_UART1
#define DEBUGGING
//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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 2/33
17/10/2019 paulfjujo.free.fr/_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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 3/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
*/
#define CLS 12
#define CR 13
#define LF 10
#define TAB 9
#define BACK 8
#define Separator 0x20 // space
#define Byte unsigned char
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 4/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 5/33
17/10/2019 paulfjujo.free.fr/_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;
float f1,f2,ff;
#include "../common/timelib.h"
TimeStruct ts1, ts2 ,ts3;
long epoch=0L ;
long epoch1=0L ;
long epoch2=0L ;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 6/33
17/10/2019 paulfjujo.free.fr/_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];
// ---------------------------------------
void Init_Hardware(void) ;
void Read_Msg_Eeprom( int depuis);
void Write_Msg_Eeprom( int Adr,const char * d1) ;
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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 7/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
#include "Fonte_Ascii_8x8.h"
}
if(RCSTA1.FERR==1 )
{
RCSTA1.SPEN = 0 ;
RCSTA1.SPEN= 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;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 8/33
17/10/2019 paulfjujo.free.fr/_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;
// }
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);
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 9/33
17/10/2019 paulfjujo.free.fr/_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;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 10/33
17/10/2019 paulfjujo.free.fr/_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
}
}
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 11/33
17/10/2019 paulfjujo.free.fr/_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;
}
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 12/33
17/10/2019 paulfjujo.free.fr/_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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 13/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
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;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 14/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
void Wait_100mS()
{
Delay_ms(100);
}
void Raz_Buffer1()
{
// nettoye le buffer
for(Index1=0;Index1<MAXLEN_BUFFER1-1;Index1++) buffer1[Index1]=0;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 15/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
i1=0;
Index1=0;
c1=0;
Flag_Buffer1 =0;
RCSTA1.CREN=0 ;
RCSTA1.CREN=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 HC06_J_Init()
{ int N; char ADDR[32];
N=0;
CRLF1();
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 16/33
17/10/2019 paulfjujo.free.fr/_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");
}
void CRLF1()
{
UART1_Write(CR);
UART1_Write(LF);
}
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 17/33
17/10/2019 paulfjujo.free.fr/_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;
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 18/33
17/10/2019 paulfjujo.free.fr/_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
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)
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 19/33
17/10/2019 paulfjujo.free.fr/_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);
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 20/33
17/10/2019 paulfjujo.free.fr/_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();
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 21/33
17/10/2019 paulfjujo.free.fr/_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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 22/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
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();
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 23/33
17/10/2019 paulfjujo.free.fr/_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);
// =================================
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 24/33
17/10/2019 paulfjujo.free.fr/_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;
RCSTA1.CREN=1;
// RCON.IPEN = 1; // enable priority levels , car TMR1 => low interrupt
PEIE_bit = 1; // Enable Peripheral interrupt
GIE_bit = 1; // Enable Global interrupt
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 25/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
// ========================================= */
Init_Module_Max7129_8x8();
UART1_Write_CText("Clear Matrice 6x 8x8\r\n" ) ;
Clear_Matrices() ;
Delay_ms(100);
Clear_Matrices() ;
Max_Timer1=10;
txt=&TEXTE[0];
Drapeaux.Temper=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 );
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 26/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
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)
{
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 27/33
17/10/2019 paulfjujo.free.fr/_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)
{
Drapeaux.Temper=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)
{
Drapeaux.Temper=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)
{
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 28/33
17/10/2019 paulfjujo.free.fr/_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= ");
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 29/33
17/10/2019 paulfjujo.free.fr/_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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 30/33
17/10/2019 paulfjujo.free.fr/_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
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 31/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
RTC Updated
New DS1307 Date :26/01/2019 New Time: 11:30:00
15.18°C
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 32/33
17/10/2019 paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c
*/
paulfjujo.free.fr/_Max7219_7seg_et_Matrice/datas/_18F46K22_test_Max71219_8xMatrice8x8_DS1307_I2C2_OWS_DS18B20_190126.c 33/33