You are on page 1of 5

#include <16f628a.

h>
#use delay(clock=4000000)
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOMCLR,NOBROWNOUT,NOLVP,NOCPD
#define data PIN_A0
#define clock PIN_A1
int8 img[] = {
0b01111110,
0b10000001,
0b10100101,
0b10000001,
0b10100101,
0b10111101,
0b10000001,
0b01111110,
};
int r = 0;
int8 chr_h[] = {
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111,
0b10000001,
0b10000001,
0b10000001,
};
int8 chr_o[] = {
0b01111110,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b01111110,
};
int8 chr_l[] = {
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b01111111,
};
int8 chr_a[] = {
0b01111110,
0b10000001,
0b10000001,
0b10000001,
0b11111111,
0b10000001,
0b10000001,
0b10000001,
};
int32 imagen[] ={
/*01234567012345670123456701234567*/
0b10001000011100001000000001110000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b11111000100010001000000011111000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b10001000011100000111100010001000,
};
const int32 imageno[] ={
/*01234567012345670123456701234567*/
0b10001000011100001000000001110000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b11111000100010001000000011111000,
0b10001000100010001000000010001000,
0b10001000100010001000000010001000,
0b10001000011100000111100010001000,
};
void show(int a[]){
img[0] = a[0];
img[1] = a[1];
img[2] = a[2];
img[3] = a[3];
img[4] = a[4];
img[5] = a[5];
img[6] = a[6];
img[7] = a[7];
}
void shw(int32 a[]){
img[0] = a[0] >> 24;
img[1] = a[1] >> 24;
img[2] = a[2] >> 24;
img[3] = a[3] >> 24;
img[4] = a[4] >> 24;
img[5] = a[5] >> 24;
img[6] = a[6] >> 24;
img[7] = a[7] >> 24;
}
void cls(){
img[0] = 0;
img[1] = 0;
img[2] = 0;
img[3] = 0;
img[4] = 0;
img[5] = 0;
img[6] = 0;
img[7] = 0;
}
void shiftl(){
imagen[0] <<= 1;
imagen[1] <<= 1;
imagen[2] <<= 1;
imagen[3] <<= 1;
imagen[4] <<= 1;
imagen[5] <<= 1;
imagen[6] <<= 1;
imagen[7] <<= 1;
}
void shiftr(){
img[0] >>= 1;
img[1] >>= 1;
img[2] >>= 1;
img[3] >>= 1;
img[4] >>= 1;
img[5] >>= 1;
img[6] >>= 1;
img[7] >>= 1;
}
#INT_TIMER1
void timertick(){
r++;
if(r%2==0) shiftl();
shw(imagen);
if(r==64){
imagen[0] = imageno[0];
imagen[1] = imageno[1];
imagen[2] = imageno[2];
imagen[3] = imageno[3];
imagen[4] = imageno[4];
imagen[5] = imageno[5];
imagen[6] = imageno[6];
imagen[7] = imageno[7];
r=0;
}
}
/*
void timertick(){
if(r==8){
show(chr_h);
}else if(r==24){
show(chr_o);
}else if(r==40){
show(chr_l);
}else if(r==56){
show(chr_a);
}else if(r==72){
cls();
}else if(r==75){
r=0;
}
r++;
}
*/
void push(byte r){
if(r==0){
output_low(data);
output_low(clock);
delay_us(1);
output_high(clock);
delay_us(1);
}else{
output_high(data);
output_low(clock);
delay_us(1);
output_high(clock);
delay_us(1);
}
}
void render(byte l){
push(~bit_test(img[l],3));
push(~bit_test(img[l],2));
push(~bit_test(img[l],1));
push(~bit_test(img[l],0));
push(~bit_test(img[l],7));
push(~bit_test(img[l],6));
push(~bit_test(img[l],5));
push(~bit_test(img[l],4));
}
void main(){
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts(GLOBAL);
enable_interrupts(INT_TIMER1);
while(1){
output_b(0b11111111);
render(0);
output_b(0b11111110);
delay_ms(2);
output_b(0b11111111);
render(1);
output_b(0b11111101);
delay_ms(2);
output_b(0b11111111);
render(2);
output_b(0b11111011);
delay_ms(2);
output_b(0b11111111);
render(3);
output_b(0b11110111);
delay_ms(2);
output_b(0b11111111);
render(4);
output_b(0b11101111);
delay_ms(2);
output_b(0b11111111);
render(5);
output_b(0b11011111);
delay_ms(2);
output_b(0b11111111);
render(6);
output_b(0b10111111);
delay_ms(2);
output_b(0b11111111);
render(7);
output_b(0b01111111);
delay_ms(2);
}
}

You might also like