zhresil som...
balu na home
balu na home
Pátek Září 11 21:44:40 CEST 2015
Cely program dole. Zacal som s arduinovymi a postupne hladal ako sa to
da napisat priamo. Takze namiesto digitalWrite(); som nasiel
DDRD = B11111110; a potom PORTD = B00000000;
To iste s casovacmi, nasiel som na internete priklady a funguje to.
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 65400; // preload timer 65536-16MHz/256/100Hz
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
Musim to prerobit na druhy (alebo treti) lebo funkcia delay podla
vsetkeho pouziva casovac 1, takisto som videl, ze sa daju robit logicke
operacie s portami, takze chcem este vyhodit digitalWrite na hybanie s
latch enable pinom.
Urcite je to z pohladu profesionala naprogramovane super prasacky, ale
zatial to funguje a celkom ma to zacalo bavit :-))
b.
On 11/09/2015 21:08, Petr Zapadlo wrote:
> Zdravím,
>
> zaujal mě ten multiplex řízený přerušením od časovače.
> Svého času jsem to hodně hledal jak na to a nenašel s tím, že arduinové
> knihovny nemají dostupný volný časovač.
> Jak to máte přesně udělané vy? Nespokytnete kousek zdrojáku?
>
> Díky
>
> Petr
>
/*
* LE - to digital pin 9
* /OE - to digital pin 10
* SDI - to digital pin 11 (MOSI pin)
* CLK - to digital pin 13 (SCK pin)
* digit1 - digital pin 7
* digit2 - digital pin 6
* digit3 - digital pin 5
* digit4 - digital pin 4
* digit5 - digital pin 3
* digit6 - digital pin 2
*/
// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the OE:
const int OE = 10;
const int LE = 9;
const byte anode[6] = {B01111111, B10111111, B11011111, B11101111,
B11110111, B11111011};
const int ascii[128] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, //0 .. 31
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, //32 .. 47, !"# $%&' ()*+ '-./
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, //48 .. 63, 0123 4567 89:; <=>?
54241,23490,39843,54017, 35523,54019,21250,56193,
3010,53297,35393,9986, 33537,11080,3912,56129, //64 .. 79, @ABC DEFG
HIJK LMNO
21442,57153,22466,55683, 20528,35649,8964,3908, 9228,8216,61445,4865,
1032,51264,1028,32769, //80 .. 95, PQRS TUVW XYZ[ \]^_
0,33299,787,515, 563,519,4866,51424, 786,768,561,9264,
48,2706,530,531, //96 .. 111 `abc defg hijk lmno
4898,18656,514,33920, 771,529,516,3588, 9228,8216,7,0, 0,0,0,0 //112
.. 127 pqrs tuvw xyz* **~*
};
const String line0 = "abcdefghijklmnop";
const String line1 = "HELLO WORLD ";
const String line2 = "Hello World ";
int character = 1;
byte digit = 0;
void setup() {
pinMode (OE, OUTPUT); // set the OE pin as an output:
pinMode (LE, OUTPUT); // set the LE pin as an output:
DDRD = B11111110; // digital pins 7,6,5,4,3,2,1,0
// initialize SPI:
SPI.begin();
digitalWrite(OE, LOW);
digitalWrite(LE, LOW);
// initialize timer1
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 65400; // preload timer 65536-16MHz/256/100Hz
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts(); // enable all interrupts
}
ISR(TIMER1_OVF_vect) // interrupt service routine that wraps a
user defined function supplied by attachInterrupt
{
TCNT1 = 65400; // preload timer
switch(digit) {
case 0:
digitalWrite(LE, LOW);
SPIWrite(ascii[line0[14]]);
SPIWrite(ascii[line0[12]]);
SPIWrite(ascii[line0[10]]);
SPIWrite(ascii[line0[8]]);
SPIWrite(ascii[line0[6]]);
SPIWrite(ascii[line0[4]]);
SPIWrite(ascii[line0[2]]);
SPIWrite(ascii[line0[0]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit++;
break;
case 1:
digitalWrite(LE, LOW);
SPIWrite(ascii[line0[15]]);
SPIWrite(ascii[line0[13]]);
SPIWrite(ascii[line0[11]]);
SPIWrite(ascii[line0[9]]);
SPIWrite(ascii[line0[7]]);
SPIWrite(ascii[line0[5]]);
SPIWrite(ascii[line0[3]]);
SPIWrite(ascii[line0[1]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit++;
break;
case 2:
digitalWrite(LE, LOW);
SPIWrite(ascii[line1[14]]);
SPIWrite(ascii[line1[12]]);
SPIWrite(ascii[line1[10]]);
SPIWrite(ascii[line1[8]]);
SPIWrite(ascii[line1[6]]);
SPIWrite(ascii[line1[4]]);
SPIWrite(ascii[line1[2]]);
SPIWrite(ascii[line1[0]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit++;
break;
case 3:
digitalWrite(LE, LOW);
SPIWrite(ascii[line1[15]]);
SPIWrite(ascii[line1[13]]);
SPIWrite(ascii[line1[11]]);
SPIWrite(ascii[line1[9]]);
SPIWrite(ascii[line1[7]]);
SPIWrite(ascii[line1[5]]);
SPIWrite(ascii[line1[3]]);
SPIWrite(ascii[line1[1]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit++;
break;
case 4:
digitalWrite(LE, LOW);
SPIWrite(ascii[line2[14]]);
SPIWrite(ascii[line2[12]]);
SPIWrite(ascii[line2[10]]);
SPIWrite(ascii[line2[8]]);
SPIWrite(ascii[line2[6]]);
SPIWrite(ascii[line2[4]]);
SPIWrite(ascii[line2[2]]);
SPIWrite(ascii[line2[0]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit++;
break;
case 5:
digitalWrite(LE, LOW);
SPIWrite(ascii[line2[15]]);
SPIWrite(ascii[line2[13]]);
SPIWrite(ascii[line2[11]]);
SPIWrite(ascii[line2[9]]);
SPIWrite(ascii[line2[7]]);
SPIWrite(ascii[line2[5]]);
SPIWrite(ascii[line2[3]]);
SPIWrite(ascii[line2[1]]);
digitalWrite(LE, HIGH); // LE pulse
digitalWrite(LE, LOW);
PORTD = anode[digit];
digit = 0;
break;
}
}
void loop() {
// main program here
}
void SPIWrite(int value) {
//digitalWrite(OE, HIGH);
SPI.transfer(highByte(value));
SPI.transfer(lowByte(value));
//digitalWrite(OE, LOW); // OE pulse
//digitalWrite(OE, HIGH);
}
Další informace o konferenci Hw-list