Before all, my english is not my native language,
so, sorry for any mystake, and more over, I'm very new in PIC world.
I'm trying to translate an old code from a user named Xor.
The original code is in MikroB, I want it in MikroC.
I working on a 16F876A with 8x8 Led matrix
Original code:
Code: Select all
' This code tested on 18F452 @ 8MHz - Default Configs
const font5x7 as byte[215] = (
$3E, $51, $49, $45, $3E,' 0
$00, $42, $7F, $40, $00,' 1
$42, $61, $51, $49, $46,' 2
$21, $41, $45, $4B, $31,' 3
$18, $14, $12, $7F, $10,' 4
$27, $45, $45, $45, $39,' 5
$3C, $4A, $49, $49, $30,' 6
$01, $71, $09, $05, $03,' 7
$36, $49, $49, $49, $36,' 8
$06, $49, $49, $29, $1E,' 9
$00, $36, $36, $00, $00,' :
$00, $56, $36, $00, $00,'
$00, $08, $14, $22, $41,' <
$14, $14, $14, $14, $14,' =
$41, $22, $14, $08, $00,' >
$02, $01, $51, $09, $06,' ?
$32, $49, $79, $41, $3E,' @
$7E, $11, $11, $11, $7E,' A
$7F, $49, $49, $49, $36,' B
$3E, $41, $41, $41, $22,' C
$7F, $41, $41, $22, $1C,' D
$7F, $49, $49, $49, $41,' E
$7F, $09, $09, $01, $01,' F
$3E, $41, $41, $51, $32,' G
$7F, $08, $08, $08, $7F,' H
$00, $41, $7F, $41, $00,' I
$20, $40, $41, $3F, $01,' J
$7F, $08, $14, $22, $41,' K
$7F, $40, $40, $40, $40,' L
$7F, $02, $04, $02, $7F,' M
$7F, $04, $08, $10, $7F,' N
$3E, $41, $41, $41, $3E,' O
$7F, $09, $09, $09, $06,' P
$3E, $41, $51, $21, $5E,' Q
$7F, $09, $19, $29, $46,' R
$46, $49, $49, $49, $31,' S
$01, $01, $7F, $01, $01,' T
$3F, $40, $40, $40, $3F,' U
$1F, $20, $40, $20, $1F,' V
$7F, $20, $18, $20, $7F,' W
$63, $14, $08, $14, $63,' X
$03, $04, $78, $04, $03,' Y
$61, $51, $49, $45, $43)' Z
sub procedure matrixchar(dim sh, indx as byte)
For ccpr1L = 1 to 15
LATB = sh
For adresh = 0 to 4
adresl = font5x7[indx+adresh]
LATC = not(adresl)
delay_5500us
LATB = LATB << 1
Next adresh
Next ccpr1l
end sub
main:
TRISB = 0
TRISC = 0
LATB = 255
LATC = 0
ADCON1 = 6
While 1=1
For ccpr1h = 0 to 211 Step 5
matrixchar(4,ccpr1h)
Next ccpr1h
ccpr2l = 1
For ccpr1h = 0 to 7
matrixchar(ccpr2l, 85)
ccpr2l = ccpr2l << 1
Next CCPR1H
ccpr2l = 128
For ccpr1h = 0 to 7
matrixchar(ccpr2l, 85)
ccpr2l = ccpr2l >> 1
Next CCPR1H
Wend
end.
Translated code:
Code: Select all
const unsigned char font8x8[152]={
0xEB, 0x81, 0x98, 0x3D, 0xBC, 0x19, 0x81, 0xD7,
0xC3, 0xC3, 0x3C, 0x24, 0x24, 0x3C, 0xC3, 0xC3,
0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff,
0xEB, 0x81, 0x98, 0x3D, 0xBC, 0x19, 0x81, 0xD7,
0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x55,
0x42, 0xC3, 0x3C, 0x24, 0x24, 0x3C, 0xC3, 0x42,
0xC3, 0xC3, 0x3C, 0x24, 0x24, 0x3C, 0xC3, 0xC3,
0xC3, 0xC3, 0x3C, 0x3C, 0x3C, 0x3C, 0xC3, 0xC3,
0xC3, 0xC3, 0x00, 0x18, 0x18, 0x00, 0xC3, 0xC3,
0xC3, 0xC3, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC3,
0x24, 0x24, 0xE7, 0x00, 0x00, 0xE7, 0x24, 0x24,
0x18, 0x24, 0x42, 0x99, 0x99, 0x42, 0x24, 0x18,
0x00, 0x62, 0x62, 0x7E, 0x62, 0x62, 0x62, 0x00,
0x00, 0x7E, 0x60, 0x78, 0x60, 0x60, 0x7E, 0x00,
0x00, 0x3C, 0x62, 0x7E, 0x62, 0x62, 0x62, 0x00,
0x00, 0x7C, 0x62, 0x7C, 0x62, 0x62, 0x62, 0x00,
0x00, 0x7E, 0x18, 0x18, 0x18, 0x18, 0x3C, 0x00,
0x00, 0x42, 0x24, 0x18, 0x18, 0x18, 0x3C, 0x00,
0x18, 0x0C, 0x06, 0xFF, 0xFF, 0x06, 0x0C, 0x18
};
void LeftScroll(int indx, int flg)
{
int t0, t1, t2, t3 ;
for (t0=0;t0<8;t0++)
{
PORTC = 1;
t3 = 0;
for (t1=0;t1<8;t1++)
{
if (t1==flg)
{
t2 = 0;
t3++;
if(t1 < 2)
{
flg = t1 + 8;
}
else
{
t2 = font8x8[indx+t1-t3];
}
}
PORTB =~t2;
delay_us(3500);
PORTC = PORTC << 1;
}
}
}
void main()
{
TRISB = 0;
TRISC = 0;
PORTC = 0;
PORTB = 0;
ADCON1 = 6;
while (1) {
ADRESL = 0;
ADRESH = 8;
while (ADRESL < 152) {
LeftScroll(ADRESL, ADRESH);
ADRESL++;
ADRESH--;
if (ADRESH == 0)
{
ADRESH = 8 ;
}
}
}
}
the display result is bad (wrong) and erratic.
Anyone can drive me on the good way?
Best regards,