TY52 보드 전광판 소스 - DOTMATRIX SLM1606M 사용
메이커활동/전자장난감 2007. 11. 17. 18:26아래에 제가 짠 소스를 올려봅니다.
대충 돌아가니까 올리기는 하는데...
아직 뭔가 조금 이상한 부분이 남아 있습니다. ^^
SLM1606M 데이타시트에 있는 Con2 부분에 대한 제어가 아직 미짐쩍어서..
하지만 신경쓰지 않기로 했습니다. ^^
SLM1608 로 바뀌면서 아예 제가 미심쩍어하는 부분은 빼버렸더군요... ^^
그냥 1606을 1608처럼 사용하는 소스...
(여전히 한군데 약간 이상한 구석(버그)이 남아있는 프로그램입니다. ^^)
혹시 SLM1606 이나 1608 구하게 되시면 이 소스 이용해서 프로그램해 보세요. ^^
연결하는 법은 소스 맨 앞쪽에 나와 있습니다.
/* ========================================= */
/* */
/* DotMatrix LED */
/* */
/* */
/* ========================================= */
/* =========================================
핀 연결 방법
1. SLM1606M 의 핀 이름
CON1 - 1 : GND
CON1 - 2 : VCC (5V)
CON2 - 1 : GND
CON2 - 2 : SELECT
CON2 - 3 : GND
CON2 - 4 : BRT-WRIGHT
CON2 - 5 : GND
CON2 - 6 : BRT-CLOCK
CON3 - 1 : GND
CON3 - 2 : RED DATA
CON3 - 3 : GND
CON3 - 4 : GREEN DATA
CON3 - 5 : GND
CON3 - 6 : CLOCK
CON3 - 7 : GND
CON3 - 8 : BRIGHT
CON3 - 9 : GND
CON3 - 10: RESET
2. TY52 보드와 SLM1606M 의 연결
TY52보드 --+-- SLM1606M
P0_0 --+-- Con3 의 2 : RED DATA
P0_1 --+-- Con3 의 4 : GREEN DATA
P0_2 --+-- Con3 의 6 : CLOCK
P0_3 --+-- Con3 의 8 : BRIGHT
P0_4 --+-- Con3 의 10: RESET
P0_5 --+-- Con2 의 6 : BRT CLOCK
P0_6 --+-- Con2 의 4 : BRT-LIGHT
P0_7 --+-- Con2 의 2 : SELECT
========================================= */
#include <AT89X52.H>
#define RED P0_0
#define GREEN P0_1
#define CLK P0_2
#define BRT P0_3
#define RST P0_4
#define BCLK P0_5
#define BWR P0_6
#define SEL P0_7
#define reload_value (256-50)
// CLK toggle period = 2 * (256-reload_value) cycles
// 1 Cycle 소요시간 : 24MHz/12 분주 => 0.0000005 sec (500ns = 0.5us)
// 1 Cycle 소요시간 : 24MHz/12 분주 * 2 * 50 => 0.00005 sec (50us)
// 1 Sec = 50us * 20,000 (회)
// #define reload_value (256-200)
typedef unsigned char u08;
void delay(void);
void showtime(void);
void mdata(u08 c, unsigned char i, unsigned char j);
void init_led(void);
void init_brt(void);
void timer0_init(void);
void timer0_end(void);
unsigned int iTime;
u08 uMat=0;
code unsigned char mat[5][16][16] = {
// Matrix 1
{
{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1},
{1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1},
{1, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1},
{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
{1, 0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0, 2, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
},
};
void mdata(u08 c, unsigned char i, unsigned char j){
RED = mat[c][i][j] & 0x01;
GREEN = (mat[c][i][j]>>1) & 0x01;
}
void showtime(void){
unsigned char i;
for(i=0;i<0xff;i++);
}
void delay(void){
_asm
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
_endasm;
}
void init_brt(void)
{
unsigned char i;
for(i=0;i<48;i++) {
SEL = 1; BRT = 1; BWR = 1;
RED = 1; GREEN = 1;
BCLK = 1; BCLK = 0;
}
}
void init_led(void){
unsigned char i,j;
timer0_end();
if(uMat==4) uMat=0;
else uMat++;
RST = 0;
RST = 1;
RST = 0;
BRT = 0;
BRT = 1;
BRT = 0;
SEL = 1; BWR = 1;
BRT = 1;
// CLK = 1; CLK = 0;
for(i=0;i<16;i++) {
for(j=0;j<16;j++) {
mdata(uMat,i,j);
CLK = 1;
CLK = 0;
}
BRT = 0;
showtime();
BRT = 1;
}
BRT = 0; SEL = 0;
timer0_init();
}
void timer0_init(void) {
TMOD &= 0xF0; /* Timer 0 mode 0 with hardware gate */
TMOD |= 0x0A; /* GATE0=1; C/T0#=0; M10=1; M00=0; */
TL0 = reload_value; /* init values */
TH0 = reload_value; /* reload value */
ET0=1; /* enable timer0 interrupt */
EA=1; /* enable interrupts */
TR0=1; /* timer0 run */
}
void timer0_end(void) {
ET0=0; /* enable timer0 interrupt */
EA=0; /* enable interrupts */
TR0=0; /* timer0 run */
}
void it_timer0(void) interrupt 1 using 1 /* interrupt address is 0x000b */
{
TF0 = 0; /* reset interrupt flag (already done by hardware)*/
CLK = !CLK; /* CLK toggle when interrupt. */
iTime++;
}
void main(void){
u08 uTime=0;
iTime = 0;
init_brt();
timer0_init();
while(1) {
if(iTime > 20000) {
P1_2 = !(P1_2);
iTime = 0;
uTime++;
if(uTime>5) { init_led(); uTime=0; }
}
}
}