📄 5x7matrix_main.c
字号:
SPPCFG = 0;
DECODER_1E = 1; //Disable Both Decoders
DECODER_2E = 1;
}
//This Function will read the data from External EEPROM to the internal RAM memory
void Fill_Buffer(unsigned short long int *addr,unsigned char bufptr)
{
unsigned char addrl;
unsigned char addrh;
unsigned char addru;
ram unsigned char i,j,k;
ram unsigned char ttotal_segment;
addrl = (unsigned char) *addr;
addrh = (unsigned char) (*addr>>8);
addru = (unsigned char) (*addr>>16);
Ex_EEPROM_Block_Select(addru); //selects Block of the External EEPROM
if(Time == 0xAA) //Display Message and Time Simultaneously
ttotal_segment = Total_Segment - 5;
else if(Time == 0x55) //Display Time Only
{
for(i=0;i<(Total_Segment*5);i++)
Buffer[i] = 0;
ttotal_segment = 0;
bufptr = bufptr+4;
}
else
ttotal_segment = Total_Segment;
for(i=0;i<ttotal_segment;i++) //Read the amount data equal to total segment
{
INTCONbits.GIE = 0;
i2c_start();
i2c_write(eeprom_write_command);
i2c_write(addrh);
i2c_write(addrl);
i2c_restart();
i2c_write(eeprom_read_command);
Buffer[bufptr] = i2c_read(1);
i2c_stop();
bufptr++;
INTCONbits.GIE = 1;
STATUSbits.C = 0;
addrl+=5;
if(STATUSbits.C)
{
STATUSbits.C = 0;
addrh++;
if(STATUSbits.C)
{
addru++;
Ex_EEPROM_Block_Select(addru);
}
}
}
if(Time == 0xAA) //Fill the Time Data in the Buffer
{
k = tcount;
for(j=0;j<5;j++)
{
Buffer[bufptr] = RTC_Buffer[k];
bufptr++;
k +=5;
}
tcount++;
}
else if(Time == 0x55)
{
k = tcount;
i = 4;
for(j=0;j<8;j++)
{
Buffer[bufptr] = RTC_Buffer[k];
bufptr++;
k+=5;
}
tcount++;
}
}
//This function fill the Readed data from the EEPROM into the latch
void Load_Latch(unsigned char bptr)
{
unsigned char i;
if(Total_Segment < 17) //Default
{
DECODER_1E = 0;
DECODER_2E = 1;
for(i=0;i<Total_Segment;i++)
{
DECODER_INPUT = ((i<<4) & 0xF0) | ((LATB & 0x0F));
// delay_us(1);
LATCH_DATA = Buffer[bptr];
bptr++;
}
}
else if(Total_Segment < 25)
{
DECODER_1E = 0;
DECODER_2E = 1;
for(i=0;i<16;i++)
{
DECODER_INPUT = ((i<<4) & 0xF0) | ((LATB & 0x0F));
// delay_us(1);
LATCH_DATA = Buffer[bptr];
bptr++;
}
DECODER_1E = 1;
LATCH_DATA = 0;
DECODER_2E = 0;
for(i=16;i<24;i++)
{
DECODER_INPUT = ((i<<4) & 0xF0) | ((LATB & 0x0F));
// delay_us(1);
LATCH_DATA = Buffer[bptr];
bptr++;
}
}
else
{
DECODER_1E = 0;
DECODER_2E = 1;
for(i=0;i<16;i++)
{
DECODER_INPUT = ((i<<4) & 0xF0) | ((LATB & 0x0F));
// delay_us(1);
LATCH_DATA = Buffer[bptr];
bptr++;
}
DECODER_1E = 1;
DECODER_2E = 0;
for(i=16;i<32;i++)
{
DECODER_INPUT = ((i<<4) & 0xF0) | ((LATB & 0x0F));
// delay_us(1);
LATCH_DATA = Buffer[bptr];
bptr++;
}
}
DECODER_1E = 1;
DECODER_2E = 1;
}
//New Message Service routine
//Get the font value followed by Data to display in ASCII format
//Every charater controller will send the ackowledgement character 'P'
//To Specify the End of Message PC must send 0x00 data to microcontroller
//and the controller will acknowledge the termination by sending the character 'O'
void New_Message()
{
ram unsigned char l,h,u,text,i,j,k,al,ah,font,width;
ram unsigned int uhl,ruhl,loc;
far rom unsigned int *ptr;
Fill_PrePost_Zero(0,0);
ah = 0;
al = Total_Segment*5;
putc_ram('F');
font = getc_ram();
while((text = getc_ram()) != 0x00)
{
text = text - 30;
ptr = &LukUpfontstart[font-1][text];
loc = *ptr;
putc_ram((unsigned char)loc);
putc_ram((unsigned char)loc>>8);
romptr = &LukUpfontwidth[font-1][text];
width = *romptr;
putc_ram(width);
romptr = &(*LukUpfont[font-1]) + loc;
for(i=0;i<width;i++)
{
Buffer[i] =*romptr;
romptr++;
}
for(i=0;i<width;i++)
putc_ram(Buffer[i]);
for(i=0;i<width;i++)
{
i2c_start();
i2c_write(EEPROM_WRITE);
i2c_write(ah);
i2c_write(al);
i2c_write(Buffer[i]);
i2c_stop();
al++;
if(al == 0)
ah++;
delay_ms(10);
}
putc_ram('P');
}
EEPROM_Write(Total_BytesL,al);
EEPROM_Write(Total_BytesH,ah);
EEPROM_Write(Total_BytesU,0);
Fill_PrePost_Zero(al,ah);
EEPROM_Write(Start_addressL,0);
EEPROM_Write(Start_addressH,0);
EEPROM_Write(Start_addressU,0);
putc_ram('O');
while(!TXSTAbits.TRMT);
}
//if Time display is enabled
//This function will fill the buffer with the time values
void Time_Display()
{
unsigned char i,tmin,thour;
far rom unsigned int *ptr;
ram unsigned int loc;
i2c_start(); //Read the values from RTC
i2c_write(RTC_WRITE);
i2c_write(0);
i2c_restart();
i2c_write(RTC_READ);
sec = i2c_read(0);
min = i2c_read(0);
hour = i2c_read(1);
i2c_stop();
i= Calculate_hour(); //Convert the hour data into segment display data
RTC_Buffer[i++] = 0x22;
RTC_Buffer[i++] = 0x00;
i = Calculate_min(i); //Convert the min data into segmnt data
if(Time == 0x55) //if its time only display its convert the sec data corresponding to display in segment
{
RTC_Buffer[i++] = 0x22;
RTC_Buffer[i++] = 0x00;
Calculate_sec(i);
}
tcount = 0;
}
unsigned char Calculate_hour(void)
{
unsigned char i,thour;
far rom unsigned int *ptr;
ram unsigned int loc;
hour = hour & 0x3F;
thour = (hour>>4) + 0x30;
hour = (hour & 0x0F) + 0x30;
ptr = &LukUpfontstart[0][thour - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(i=0;i<6;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
ptr = &LukUpfontstart[0][hour - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(;i<12;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
return i;
}
unsigned char Calculate_min(unsigned char i)
{
unsigned char tmin,ttt;
far rom unsigned int *ptr;
ram unsigned int loc;
ttt = i+6;
tmin = (min>>4) + 0x30;
min = (min & 0x0F) + 0x30;
ptr = &LukUpfontstart[0][tmin - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(;i<ttt;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
ttt+=6;
ptr = &LukUpfontstart[0][min - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(;i<ttt;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
return i;
}
void Calculate_sec(unsigned char i)
{
unsigned char tsec,ttt;
far rom unsigned int *ptr;
ram unsigned int loc;
ttt = i+6;
tsec = (sec>>4) + 0x30;
sec = (sec & 0x0F) + 0x30;
ptr = &LukUpfontstart[0][tsec - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(;i<ttt;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
ttt+=6;
ptr = &LukUpfontstart[0][sec - 30];
loc = *ptr;
romptr = &(*LukUpfont[0]) + loc;
for(;i<ttt;i++)
{
RTC_Buffer[i] =*romptr;
romptr++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -