Skip to content

Instantly share code, notes, and snippets.

@enjoycowboy
Forked from Ravensgun/matriz
Last active March 24, 2017 16:04
Show Gist options
  • Save enjoycowboy/93e487e199ee97b24b0de8fb098b8048 to your computer and use it in GitHub Desktop.
Save enjoycowboy/93e487e199ee97b24b0de8fb098b8048 to your computer and use it in GitHub Desktop.
reveiw 1 que compilou no arduino
/*
0123456701234567
0 0000000000000000
1 0000011100001000
2 0000100000100010
3 0000011100001110
4 0000000000000010
0 0000011000000000
1 0000100100011100
2 0000100100001010
3 0000011000011101
4 0000000000000000
0 0000111100000000
1 0000100000000000
2 0000100000000000
3 0000000100000000
4 0000111100000000
0 0000000100000000
1 0000110000000000
2 0001001000000000
3 0001001000000000
4 0000110000000000
*/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
volatile unsigned int varredura1[5][2]={{0x00, 0x00}, //bota na linha
{0x07, 0x08}, // cada um dos
{0x08, 0x48}, // bits pra formar
/*latch 1*/ {0x70, 0x1c},// o segmento
{0x00, 0x20}};
volatile unsigned int varredura2[5][2]={{0x30, 0x00},
{0x48, 0x50},
{0x30, 0xb8},
/*latch2*/ {0x00, 0x00},
{0xF0, 0x00}};
volatile unsigned int varredura3[5][2]={{0x10, 0x00},
{0x10, 0x00},
{0x80, 0x00},
/*latch3*/ {0xf0, 0x00},
{0x80, 0x00}};
volatile unsigned int varredura4[5][2]={{0x80, 0x00},
{0x30, 0x00},
{0x48, 0x00},
/*latch4*/ {0x48, 0x00},
{0x30, 0x00}};
void BangBit1(void);
void BangBit2(void);
void BangBit3(void);
void BangBit4(void);
int main()
{
//valores de acordo com a progressão do clock
int Latch1, Latch2, Latch3, Latch4 = 0; //bits na linha do latch
int ClockShift=0; // controle da progressão do clock
DDRD =0xff; // os transistores na linha
DDRC =0xff; // o bit no latch
DDRB =0xff; // o clock do latch
while(1)
{
BangBit1();
BangBit2();
BangBit3();
BangBit4();
}
}
void BangBit1(void){
int i=0;
for (i=0; i>=8; i++)
{
if (i==0)
{
PORTC = (1<<PORTC0); // joga 1 no latch
}
PORTC = 0;
PORTB = (1<<PORTB0); //cloca a o latch (STCP)
PORTD = ((varredura1[0][1] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura1[1][1] >> i)<<PORTD1); //pq tipo o valor que eutenho que passar é em serial
PORTD = ((varredura1[2][1] >> i)<<PORTD2); //ento se eu deslocar o bit a cada iteração, ele vai passar
PORTD = ((varredura1[3][1] >> i)<<PORTD3); //cada um em serial, pq, eu preciso passar tipo 101111011 pro latch
PORTD = ((varredura1[4][1] >> i)<<PORTD4); //aí se eu deslocar dentro do registrador, ele vai passar um valor por vez
PORTB = (0<<PORTB1); //descloca o latch. essa parte aqui não tá fazendo o que pra fazer. problema de bios
}
for (i=8; i>=16; i++)
{
if (i == 8)
{
PORTC = (1<<PORTC0); // joga 1 no latch
}
PORTB = (1<<PORTB1);
PORTD = ((varredura1[0][2] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura1[1][2] >> i)<<PORTD1); //aí esse pedaço faz a mesma coisa mas pros proximos 8 bits que tem que ser jogado na tela
PORTD = ((varredura1[2][2] >> i)<<PORTD2);
PORTD = ((varredura1[3][2] >> i)<<PORTD3); //só que eu tava com sono pra caralho aí nao pensei direito, mas isso aqui ta tudo zuado
PORTD = ((varredura1[4][2] >> i)<<PORTD4);
PORTB = (0<<PORTB0);
}
}
void BangBit2(void){
int i=0;
for (i=0; i>=8; i++)
{
if (i==0)
{
PORTC = (1<<PORTC1); // joga 1 no latch
}
PORTB = (1<<PORTB1);
PORTD = ((varredura2[0][1] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura2[1][1] >> i)<<PORTD1);
PORTD = ((varredura2[2][1] >> i)<<PORTD2);
PORTD = ((varredura2[3][1] >> i)<<PORTD3); // o resto foi copia ecola pq sono
PORTD = ((varredura2[4][1] >> i)<<PORTD4);
PORTB = (0<<PORTB1);
}
for (i=8; i>=16; i++)
{
if (i == 8)
{
PORTC = (1<<PORTC0); // joga 1 no latch
}
PORTB = (1<<PORTB1);
PORTD = ((varredura2[0][2] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura2[1][2] >> i)<<PORTD1);
PORTD = ((varredura2[2][2] >> i)<<PORTD2);
PORTD = ((varredura2[3][2] >> i)<<PORTD3);
PORTD = ((varredura2[4][2] >> i)<<PORTD4);
PORTB = (0<<PORTB1);
}
}
void BangBit3(void){
int i=0;
for (i=0; i>=8; i++)
{
if (i==0)
{
PORTC = (1<<PORTC2); // joga 1 no latch
}
PORTB = (1<<PORTB2);
PORTD = ((varredura3[0][1] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura3[1][1] >> i)<<PORTD1);
PORTD = ((varredura3[2][1] >> i)<<PORTD2);
PORTD = ((varredura3[3][1] >> i)<<PORTD3);
PORTD = ((varredura3[4][1] >> i)<<PORTD4);
PORTB = (0<<PORTB2);
}
for (i=8; i>=16; i++)
{
if (i == 8)
{
PORTC = (1<<PORTC0); // joga 1 no latch
}
PORTB = (1<<PORTB2);
PORTD = ((varredura3[0][2] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura3[1][2] >> i)<<PORTD1);
PORTD = ((varredura3[2][2] >> i)<<PORTD2);
PORTD = ((varredura3[3][2] >> i)<<PORTD3);
PORTD = ((varredura3[4][2] >> i)<<PORTD4);
PORTB = (0<<PORTB2);
}
}
void BangBit4(void){
int i=0;
for (i=0; i>=8; i++)
{
if (i==0)
{
PORTC = (1<<PORTC3); // joga 1 no latch
}
PORTB = (1<<PORTB3);
PORTD = ((varredura4[0][1] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura4[1][1] >> i)<<PORTD1);
PORTD = ((varredura4[2][1] >> i)<<PORTD2);
PORTD = ((varredura4[3][1] >> i)<<PORTD3);
PORTD = ((varredura4[4][1] >> i)<<PORTD4);
PORTB = (0<<PORTB3);
}
for (i=8; i>=16; i++)
{
if (i == 8)
{
PORTC = (1<<PORTC0); // joga 1 no latch
}
PORTB = (1<<PORTB3);
PORTD = ((varredura4[0][2] >> i)<<PORTD0); //usa o deslocamento pra serializar o bit
PORTD = ((varredura4[1][2] >> i)<<PORTD1);
PORTD = ((varredura4[2][2] >> i)<<PORTD2);
PORTD = ((varredura4[3][2] >> i)<<PORTD3);
PORTD = ((varredura4[4][2] >> i)<<PORTD4);
PORTB = (0<<PORTB3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment