pravin b
Member level 5
- Joined
- May 20, 2012
- Messages
- 85
- Helped
- 2
- Reputation
- 4
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Mumbai, India
- Activity points
- 2,083
http://forum.freetronics.com/viewtopic.php?t=5754
#include <htc.h>
#include "include.h"
// PIC16F1939 Configuration Bit Settings
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
__CONFIG(WRT_OFF & VCAPEN_OFF & PLLEN_ON & STVREN_ON & BORV_LO & LVP_OFF);
// a b c d
unsigned char dmdbuff[16][4]={//C0 C1 C2 C3
{0x00,0x00,0x00,0x00}, //R0
{0x00,0x00,0x00,0x00}, //R1
{0x00,0x00,0x00,0x00}, //R2
{0x00,0x00,0x00,0x00}, //R3
{0x00,0x00,0x00,0x00}, //R4
{0x00,0x00,0x00,0x00}, //R5
{0x00,0x00,0x00,0x00}, //R6
{0x00,0x00,0x00,0x00}, //R7
{0x00,0x20,0x00,0x04}, //R8
{0x38,0x20,0x38,0x04}, //R9
{0x44,0x2c,0x44,0x34}, //R10
{0x04,0x32,0x40,0x4c}, //R11
{0x3c,0x22,0x40,0x44}, //R12
{0x44,0x32,0x40,0x44}, //R13
{0x44,0x32,0x44,0x4c}, //R14
{0x38,0x2c,0x38,0x34}, //R15
};
char row,x,y;
void main()
{
system_init();
while(1)
{
show_row(0);
show_row(1);
show_row(2);
show_row(3);
}
}
void system_init()
{
OSCCON = 0b01110000; // 32 MHz Fosc w/ PLLEN_ON (config bit)
TRISC=0b00000000;
// PORTC=0;
TRISD0=0;
pin=0;
// USART_Init();
// ms1_delay(100);
// USART_putstring("UART_OK\r");
swspi_init();
}
void show_row(char temp)
{
for(y=0;y<=3;y++)
{
swspi_write_byte(dmdbuff[(16-4)+temp][y]);
swspi_write_byte(dmdbuff[(16-8)+temp][y]);
swspi_write_byte(dmdbuff[(16-12)+temp][y]);
swspi_write_byte(dmdbuff[(16-16)+temp][y]);
}
P10_LATCH=1;
us500_delay(1);
P10_LATCH=0;
scan_row(temp);
DISP_EN=0;
}
void scan_row(char temp)
{
switch(temp)
{
case 0: P10_A=0;
P10_B=0;
break;
case 1: P10_A=1;
P10_B=0;
break;
case 2: P10_A=0;
P10_B=1;
break;
case 3: P10_A=1;
P10_B=1;
break;
default:P10_A=0;
P10_B=0;
break;
}
}
void ms1_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=568;j++);
}
void us500_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=284;j++);
}
void interrupt my_ISR()
{
if(RCIF)
{
USARTdataready=1;
rx_byte=RCREG;
if(FERR || OERR)
CREN=0;
USART_putchar(rx_byte);
RCIF=0;
get_data();
}
}
void swspi_init( void )
{
P10_A=0;
P10_B=0;
P10_PWM=0;
P10_SCK=0;
DISP_EN=1;
P10_DATA=0;
P10_LATCH=0;
}
/*************************************
write value to register
**************************************/
void swspi_write_byte(unsigned int temp)
{
unsigned char n=8;
// DISP_EN = 0;
// temp |= 0x80;
// P10_SCK = 0;
while(n--)
{
P10_SCK = 0;
if(temp&0x80)
P10_DATA=1;
else
P10_DATA=0;
P10_SCK = 1;
temp <<= 1;
}
NOP();
// DISP_EN = 1;
}
#define P10_A RC0
#define P10_B RC1
#define P10_PWM RC2
#define P10_SCK RC3
#define DISP_EN RC4
#define P10_DATA RC5
#define P10_LATCH RC6
call of showrow(0):DisplayRam[12][0]>DisplayRam[8][0]>DisplayRam[4][0]>DisplayRam[0][0]>DisplayRam[13][0]>DisplayRam[9][0]>DisplayRam[5][0]>DisplayRam[1][0]>DisplayRam[14][0]>DisplayRam[10][0]>DisplayRam[6][0]>DisplayRam[2][0]>DisplayRam[15][0]>DisplayRam[11][0]>DisplayRam[7][0]>DisplayRam[3][0]
call of showrow(1):DisplayRam[12][1]>DisplayRam[8][1]>DisplayRam[4][1]>DisplayRam[0][1]>DisplayRam[13][1]>DisplayRam[9][1]>DisplayRam[5][1]>DisplayRam[1][1]>DisplayRam[14][1]>DisplayRam[10][1]>DisplayRam[6][1]>DisplayRam[2][1]>DisplayRam[15][1]>DisplayRam[11][1]>DisplayRam[7][1]>DisplayRam[3][1]
& so on....
Doesn't apply here. "P10" LED module is a ready made module with serial mux interface.Pins on one side of the matrix display connect to anodes and the pins on another side connect to cathodes. Have you connected anodes and cathodes properly ?
#include <htc.h>
#include "include.h"
// PIC16F1939 Configuration Bit Settings
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
__CONFIG(WRT_OFF & VCAPEN_OFF & PLLEN_ON & STVREN_ON & BORV_LO & LVP_OFF);
//// a b c d
//unsigned char dmdbuff[16][4]={//C0 C1 C2 C3
// {0x00,0x00,0x00,0x00}, //R0
// {0x00,0x00,0x00,0x00}, //R1
// {0x00,0x00,0x00,0x00}, //R2
// {0x00,0x00,0x00,0x00}, //R3
// {0x00,0x00,0x00,0x00}, //R4
// {0x00,0x00,0x00,0x00}, //R5
// {0x00,0x00,0x00,0x00}, //R6
// {0x00,0x00,0x00,0x00}, //R7
// {0x00,0x20,0x00,0x04}, //R8
// {0x38,0x20,0x38,0x04}, //R9
// {0x44,0x2c,0x44,0x34}, //R10
// {0x04,0x32,0x40,0x4c}, //R11
// {0x3c,0x22,0x40,0x44}, //R12
// {0x44,0x32,0x40,0x44}, //R13
// {0x44,0x32,0x44,0x4c}, //R14
// {0x38,0x2c,0x38,0x34}, //R15
// };
unsigned char dmdbuff[16][4]={//C0 C8 C16 C24C31
{0x00,0x00,0x00,0x00}, //R0
{0xFF,0x00,0x00,0x00}, //R1
{0xFF,0x00,0x00,0x00}, //R2
{0x00,0x00,0x00,0x00}, //R3
{0x00,0x00,0x00,0x00}, //R4
{0x00,0x00,0x00,0x00}, //R5
{0x00,0x00,0x00,0x00}, //R6
{0x00,0x00,0x00,0x00}, //R7
{0x00,0x00,0x00,0x00}, //R8
{0x00,0x00,0x00,0x00}, //R9
{0x00,0x00,0x00,0x00}, //R10
{0x00,0x00,0x00,0x00}, //R11
{0x00,0x00,0x00,0x00}, //R12
{0x00,0x00,0x00,0x00}, //R13
{0x00,0x00,0x00,0x00}, //R14
{0x00,0x00,0x00,0x00}, //R15
};
char y;
void main()
{
system_init();
while(1)
{
show_row(0);
show_row(1);
show_row(2);
show_row(3);
// while(1);
}
}
void system_init()
{
OSCCON = 0b01110000; // 32 MHz Fosc w/ PLLEN_ON (config bit)
TRISA=0b11111111;
TRISB=0b11111111;
TRISC=0b00000000;
TRISD=0b11111110;
TRISE=0b1111;
pin=0;
USART_Init();
ms1_delay(100);
USART_putstring("UART_OK\r");
swspi_init();
}
void show_row(char temp1)
{
DISP_EN=1;
scan_row(temp1);
for(y=0;y<=3;y++)
{
swspi_write_byte(~dmdbuff[(16-4)+temp1][y]);
// sprintf(sbuff,"X-%02d, Y-%02d\r",(16-4)+temp1,y); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
swspi_write_byte(~dmdbuff[(16-8)+temp1][y]);
// sprintf(sbuff,"X-%02d, Y-%02d\r",(16-8)+temp1,y); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
swspi_write_byte(~dmdbuff[(16-12)+temp1][y]);
// sprintf(sbuff,"X-%02d, Y-%02d\r",(16-12)+temp1,y); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
swspi_write_byte(~dmdbuff[(16-16)+temp1][y]);
// sprintf(sbuff,"X-%02d, Y-%02d\r",(16-16)+temp1,y); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
}
P10_LATCH=1;
us5_delay(1);
P10_LATCH=0;
DISP_EN=0;
// us500_delay(1);
}
void scan_row(char temp2)
{
switch(temp2)
{
case 0: P10_A=0;
P10_B=0;
break;
case 1: P10_A=1;
P10_B=0;
break;
case 2: P10_A=0;
P10_B=1;
break;
case 3: P10_A=1;
P10_B=1;
break;
default:P10_A=0;
P10_B=0;
break;
}
// sprintf(sbuff,"%d_A=%d, B=%d\r",temp2,P10_A,P10_B);
// USART_putstring(sbuff);
}
void ms1_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=568;j++);
}
void us500_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=284;j++);
}
void us5_delay(unsigned int c)
{
unsigned int i;
for(i=1;i<=c;i++)
{
NOP();
}
}
void interrupt my_ISR()
{
if(RCIF)
{
USARTdataready=1;
rx_byte=RCREG;
if(FERR || OERR)
CREN=0;
USART_putchar(rx_byte);
RCIF=0;
get_data();
}
}
void show_row(char temp1)
{
// P10_EN=1;
for(y=0;y<=3;y++)
{
swspi_write_byte(~dmdbuff[(16-4)+temp1][y]);
swspi_write_byte(~dmdbuff[(16-8)+temp1][y]);
swspi_write_byte(~dmdbuff[(16-12)+temp1][y]);
swspi_write_byte(~dmdbuff[(16-16)+temp1][y]);
// sprintf(sbuff,"X-%02d, Y-%02d\r_A=%d, B=%d; temp1=%d\r",(16-16)+temp1,y,P10_A,P10_B,temp1); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
}
P10_LATCH=1;
us5_delay(1);
P10_LATCH=0;
scan_row(temp1);
P10_EN=1;
us5_delay(10);
P10_EN=0;
us5_delay(180);
}
Wrong signal timing.however i can see "ghosting" of one column behind each character.
/* scrolling effects:
*show_string(0,"abcd") - Scrolls text Right to Left (default mode)
*show_string(1,"abcd") - Scrolls text Left to Right
* problem: scroll left to right yet to be checked.
*/
#include "include.h"
#include "myfont.h"
//#include "Terminal_font_12x16.h"
// PIC16F1939 Configuration Bit Settings
__CONFIG(FOSC_INTOSC & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & CLKOUTEN_OFF & IESO_OFF & FCMEN_OFF);
__CONFIG(WRT_OFF & VCAPEN_OFF & PLLEN_ON & STVREN_ON & BORV_LO & LVP_OFF);
//// a b c d
/*unsigned char dmdbuff[16][4]={//C0 C1 C2 C3
{0x00,0x00,0x00,0x00}, //R0
{0x00,0x00,0x00,0x00}, //R1
{0x00,0x00,0x00,0x00}, //R2
{0x00,0x00,0x00,0x00}, //R3
{0x00,0x00,0x00,0x00}, //R4
{0x00,0x00,0x00,0x00}, //R5
{0x00,0x00,0x00,0x00}, //R6
{0x00,0x00,0x00,0x00}, //R7
{0x00,0x20,0x00,0x04}, //R8
{0x38,0x20,0x38,0x04}, //R9
{0x44,0x2c,0x44,0x34}, //R10
{0x04,0x32,0x40,0x4c}, //R11
{0x3c,0x22,0x40,0x44}, //R12
{0x44,0x32,0x40,0x44}, //R13
{0x44,0x32,0x44,0x4c}, //R14
{0x38,0x2c,0x38,0x34}, //R15
};*/
unsigned char dmdbuff[16][4]={0};
char y,k=3,rcount=0;
void main()
{
system_init();
while(1)
{
show_string(0,"hello world");
}
}
void system_init()
{
OSCCON = 0b01110000; // 32 MHz Fosc w/ PLLEN_ON (config bit)
TRISA=0b11111111;
TRISB=0b11111111;
TRISD=0b11111110;
TRISE=0b1111;
test_led=0;
test_led_DIR=0;
USART_Init();
ms1_delay(100);
USART_putstring("UART_OK\r");
hwspi_init();
timer1_init();
}
void clear_display()
{
char crow,ccol;
for(crow=0;crow<16;crow++)
{
hwspi_write_byte(0xff);
}
P10_LATCH=1;
NOP();
NOP();
P10_LATCH=0;
}
void show_row(char temp1)
{
for(y=0;y<=3;y++)
{
hwspi_write_byte(~dmdbuff[(16-4)+temp1][y]);
hwspi_write_byte(~dmdbuff[(16-8)+temp1][y]);
hwspi_write_byte(~dmdbuff[(16-12)+temp1][y]);
hwspi_write_byte(~dmdbuff[(16-16)+temp1][y]);
// sprintf(sbuff,"X=%02d, Y=%02d, temp1=%d\r_A=%d, B=%d\r",(16-16)+temp1,y,temp1,P10_A,P10_B); //for debugging on UART
// USART_putstring(sbuff); //for debugging on UART
}
P10_LATCH=1;
NOP();
NOP();
P10_LATCH=0;
}
void update_display_R_L(unsigned int pos)
{
char fontwidth, row, col,width,m;
width=font8x8[pos][0];
for(fontwidth=0;fontwidth<=7;fontwidth++)
{
for(row=0;row<=15;row++)
{
for(col=0;col<=3;col++)
{
dmdbuff[row][col]<<=1;
if(col<3)
{
if(dmdbuff[row][col+1]&0x80)
dmdbuff[row][col]|=0x01;
}
else
{
if(font8x8[pos][row]&(0x80>>fontwidth))
dmdbuff[row][col]|=0x01;
}
}
}
ms1_delay(50); //increase delay count to reduce speed.
}
}
void update_display_L_R(unsigned int pos)
{
signed char fontwidth, row, width, col, m;
width=font8x8[pos][0];
// test_led=1;
for(fontwidth=0;fontwidth<=7;fontwidth++)
{
for(row=0;row<=15;row++)
{
for(col=3;col>=0;col--)
{
dmdbuff[row][col]>>=1;
if(col>0)
{
if(dmdbuff[row][col-1]&0x01)
dmdbuff[row][col]|=0x80;
}
else if(col==0)
{
if(font8x8[pos][row]&(0x01<<fontwidth))
dmdbuff[row][col]|=0x80;
}
}
}
// test_led=0;
// display();
ms1_delay(50); //increase delay count to reduce speed.
}
// for(m=0;m<=15;m++)
// {
// sprintf(sbuff,"AL%03d, %03d, %03d, %03d\r",dmdbuff[m][0],dmdbuff[m][1],dmdbuff[m][2],dmdbuff[m][3]);
// USART_putstring(sbuff);
// }
}
void show_string(char style, char *str1)
{
signed char i,msg_len, row, instring[5], col,m;
char ;
// if(dupdate)
// msg_len=slen;
// else
msg_len=strlen(str1);
if(msg_len<5)
{
// strcpy(instring,str1);
// str1[msg_len]='a'
// sprintf(sbuff,"old str: %s\r",instring);
// USART_putstring(sbuff);;
// strncat(instring," ",4-msg_len);
// USART_putstring(instring);
for(col=0;col<msg_len;col++)
{
for(row=0;row<=15;row++)
{
dmdbuff[row][col]=font8x8[(*str1)-32][row];
}
str1++;
}
}
else
{
switch(style)
{
case 0:
for(i=0;i<msg_len;i++)
{
update_display_R_L((*str1)-32);
str1++;
}
break;
case 1: for(i=msg_len-1;i>=0;i--)
{
update_display_L_R((str1[i])-97);
sprintf(sbuff,"value: %c, i=%d\r",str1[i],i);
USART_putstring(sbuff);
}
break;
default:for(i=0;i<msg_len;i++)
{
update_display_R_L((*str1)-97);
str1++;
}
break;
}
}
}
void timer1_init()
{
GIE=1;
PEIE=1;
T1CON=0b00000100;
TMR1IE=1;
TMR1IF=0;
TMR1=0xe700; //display updated on every 800usec
TMR1ON=1;
}
void ms1_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=568;j++);
}
void us500_delay(unsigned int c)
{
unsigned int i,j;
for(i=1;i<=c;i++)
for(j=0;j<=284;j++);
}
void us5_delay(unsigned int c)
{
unsigned int i;
for(i=1;i<=c;i++)
{
NOP();
}
}
void interrupt my_ISR()
{
if(RCIF)
{
USARTdataready=1;
rx_byte=RCREG;
if(FERR || OERR)
CREN=0;
USART_putchar(rx_byte);
RCIF=0;
get_data();
}
if(TMR1IF) //update display on every T1 overflow
{
// test_led=~test_led;
TMR1IF=0;
TMR1=0xe700; //800us
switch(rcount)
{
case 0: P10_EN=0;
show_row(rcount);
P10_A=0;
P10_B=0;
P10_EN=1;
break;
case 1: P10_EN=0;
show_row(rcount);
P10_A=1;
P10_B=0;
P10_EN=1;
break;
case 2: P10_EN=0;
show_row(rcount);
P10_A=0;
P10_B=1;
P10_EN=1;
break;
case 3: P10_EN=0;
show_row(rcount);
P10_A=1;
P10_B=1;
P10_EN=1;
break;
}
rcount++;
if(rcount>3)
rcount=0;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?