De0NanoExtension : Différence entre versions
m (→{{Rouge|Premiere partie}}) |
m (→Projet carte extension pour DE0 (Violette et Villaire)) |
||
Ligne 6 : | Ligne 6 : | ||
===uefh=== | ===uefh=== | ||
==efhzepfze== | ==efhzepfze== | ||
+ | =Tests= | ||
+ | Nous avons décidé de tester la carte avec une carte Arduino UNO. Le programme utilisé est : | ||
+ | <source lang=c> | ||
+ | /* Define shift register pins used for seven segment display */ | ||
+ | #define LATCH_DIO 4 | ||
+ | #define CLK_DIO 7 | ||
+ | #define DATA_DIO 8 | ||
+ | |||
+ | /* Segment byte maps for numbers 0 to 9 */ | ||
+ | const byte SEGMENT_MAP[] = { | ||
+ | 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90}; | ||
+ | /* Byte maps to select digit 1 to 4 */ | ||
+ | const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8}; | ||
+ | |||
+ | byte x=0; | ||
+ | byte x1=0; | ||
+ | byte x2=0; | ||
+ | byte x3=0; | ||
+ | |||
+ | #define PinA 1 // 1ere sortie du codeur | ||
+ | #define PinB 0 // 2e sortie du codeur | ||
+ | |||
+ | volatile boolean mouvement; | ||
+ | volatile boolean up; | ||
+ | |||
+ | unsigned int valeur = 0; | ||
+ | |||
+ | // routine déclanchée quand le signal A passe de haut a bas | ||
+ | |||
+ | |||
+ | void setup () | ||
+ | { | ||
+ | /* Set DIO pins to outputs */ | ||
+ | pinMode(LATCH_DIO,OUTPUT); | ||
+ | pinMode(CLK_DIO,OUTPUT); | ||
+ | pinMode(DATA_DIO,OUTPUT); | ||
+ | |||
+ | pinMode(PinA,INPUT); | ||
+ | pinMode(PinB,INPUT); | ||
+ | |||
+ | // activation des pullups internes de l'Arduino, si on n'utilise pas de pullups externes. | ||
+ | // digitalWrite (PinA, HIGH); | ||
+ | // digitalWrite (PinB, HIGH); | ||
+ | |||
+ | attachInterrupt (0,routineInterruption,FALLING); // interruption sur front descendant | ||
+ | |||
+ | Serial.begin (9600); // initialisation du moniteur série | ||
+ | Serial.println("Veuillez tourner le bouton"); | ||
+ | } | ||
+ | |||
+ | void routineInterruption () { | ||
+ | //if (digitalRead(PinA)) | ||
+ | up = digitalRead(PinA); | ||
+ | |||
+ | // else | ||
+ | // up = !digitalRead(PinB); | ||
+ | mouvement = true; | ||
+ | } | ||
+ | |||
+ | |||
+ | /* Main program */ | ||
+ | void loop() | ||
+ | { | ||
+ | |||
+ | /* Update the display with the current counter value */ | ||
+ | |||
+ | |||
+ | if (mouvement) { // on a détecté une rotation du bouton | ||
+ | if (up) | ||
+ | //valeur++; | ||
+ | incrementBCD(&valeur); | ||
+ | else | ||
+ | //valeur--; | ||
+ | decrementBCD(&valeur); | ||
+ | mouvement= false; | ||
+ | |||
+ | Serial.println (valeur); | ||
+ | |||
+ | } | ||
+ | |||
+ | WriteNumberToSegment(0 , (valeur&0xF000)>>12); | ||
+ | delay(1); | ||
+ | WriteNumberToSegment(1 , (valeur&0x0F00)>>8); | ||
+ | delay(1); | ||
+ | WriteNumberToSegment(2 , (valeur&0x00F0)>>4); | ||
+ | delay(1); | ||
+ | WriteNumberToSegment(3 , (valeur&0x000F)); | ||
+ | delay(1); | ||
+ | } | ||
+ | |||
+ | /* Write a decimal number between 0 and 9 to one of the 4 digits of the display */ | ||
+ | void WriteNumberToSegment(byte Segment, byte Value) | ||
+ | { | ||
+ | digitalWrite(LATCH_DIO,LOW); | ||
+ | shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]); | ||
+ | shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] ); | ||
+ | digitalWrite(LATCH_DIO,HIGH); | ||
+ | } | ||
+ | |||
+ | void incrementBCD(unsigned int *cnt) { | ||
+ | (*cnt)++; | ||
+ | if ((*cnt & 0x000F) > 0x0009) *cnt += 6; | ||
+ | if ((*cnt & 0x00F0) > 0x0090) *cnt += 0x0060; | ||
+ | if ((*cnt & 0x0F00) > 0x0900) *cnt += 0x0600; | ||
+ | if ((*cnt & 0xF000) > 0x9000) *cnt += 0x6000; | ||
+ | } | ||
+ | |||
+ | void decrementBCD(unsigned int *cnt) { | ||
+ | (*cnt)--; | ||
+ | if ((*cnt & 0x000F) == 0x000F) *cnt -= 6; | ||
+ | if ((*cnt & 0x00F0) == 0x00F0) *cnt -= 0x0060; | ||
+ | if ((*cnt & 0x0F00) == 0x0F00) *cnt -= 0x0600; | ||
+ | if ((*cnt & 0xF000) == 0xF000) *cnt -= 0x6000; | ||
+ | } | ||
+ | |||
+ | |||
+ | </source> |
Version du 18 janvier 2017 à 17:21
Sommaire
[masquer]Premiere partie
Projet carte extension pour DE0 (Violette et Villaire)
izerriogj
uefh
efhzepfze
Tests
Nous avons décidé de tester la carte avec une carte Arduino UNO. Le programme utilisé est :
/* Define shift register pins used for seven segment display */
#define LATCH_DIO 4
#define CLK_DIO 7
#define DATA_DIO 8
/* Segment byte maps for numbers 0 to 9 */
const byte SEGMENT_MAP[] = {
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
/* Byte maps to select digit 1 to 4 */
const byte SEGMENT_SELECT[] = {0xF1,0xF2,0xF4,0xF8};
byte x=0;
byte x1=0;
byte x2=0;
byte x3=0;
#define PinA 1 // 1ere sortie du codeur
#define PinB 0 // 2e sortie du codeur
volatile boolean mouvement;
volatile boolean up;
unsigned int valeur = 0;
// routine déclanchée quand le signal A passe de haut a bas
void setup ()
{
/* Set DIO pins to outputs */
pinMode(LATCH_DIO,OUTPUT);
pinMode(CLK_DIO,OUTPUT);
pinMode(DATA_DIO,OUTPUT);
pinMode(PinA,INPUT);
pinMode(PinB,INPUT);
// activation des pullups internes de l'Arduino, si on n'utilise pas de pullups externes.
// digitalWrite (PinA, HIGH);
// digitalWrite (PinB, HIGH);
attachInterrupt (0,routineInterruption,FALLING); // interruption sur front descendant
Serial.begin (9600); // initialisation du moniteur série
Serial.println("Veuillez tourner le bouton");
}
void routineInterruption () {
//if (digitalRead(PinA))
up = digitalRead(PinA);
// else
// up = !digitalRead(PinB);
mouvement = true;
}
/* Main program */
void loop()
{
/* Update the display with the current counter value */
if (mouvement) { // on a détecté une rotation du bouton
if (up)
//valeur++;
incrementBCD(&valeur);
else
//valeur--;
decrementBCD(&valeur);
mouvement= false;
Serial.println (valeur);
}
WriteNumberToSegment(0 , (valeur&0xF000)>>12);
delay(1);
WriteNumberToSegment(1 , (valeur&0x0F00)>>8);
delay(1);
WriteNumberToSegment(2 , (valeur&0x00F0)>>4);
delay(1);
WriteNumberToSegment(3 , (valeur&0x000F));
delay(1);
}
/* Write a decimal number between 0 and 9 to one of the 4 digits of the display */
void WriteNumberToSegment(byte Segment, byte Value)
{
digitalWrite(LATCH_DIO,LOW);
shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_MAP[Value]);
shiftOut(DATA_DIO, CLK_DIO, MSBFIRST, SEGMENT_SELECT[Segment] );
digitalWrite(LATCH_DIO,HIGH);
}
void incrementBCD(unsigned int *cnt) {
(*cnt)++;
if ((*cnt & 0x000F) > 0x0009) *cnt += 6;
if ((*cnt & 0x00F0) > 0x0090) *cnt += 0x0060;
if ((*cnt & 0x0F00) > 0x0900) *cnt += 0x0600;
if ((*cnt & 0xF000) > 0x9000) *cnt += 0x6000;
}
void decrementBCD(unsigned int *cnt) {
(*cnt)--;
if ((*cnt & 0x000F) == 0x000F) *cnt -= 6;
if ((*cnt & 0x00F0) == 0x00F0) *cnt -= 0x0060;
if ((*cnt & 0x0F00) == 0x0F00) *cnt -= 0x0600;
if ((*cnt & 0xF000) == 0xF000) *cnt -= 0x6000;
}