Minitel/Mininet
De FunLab Documentation
/*
Programme de communication série avec un minitel.
Modification du code original de TetaLab.
Au démarrage du minitel:
Fnct+P puis 4 pour passer en 4800 bauds (1200 par défaut)
Fnct+T puis E pour désactiver l'écho local
*/
#include <SoftwareSerial.h>
int minled=13;
int usbled=6;
SoftwareSerial Minitel(7,8); // master
SoftwareSerial Minitelsl1(9,10); // RX, TX
SoftwareSerial Minitelsl2(11,12); // RX, TX
void setup()
{
pinMode(usbled,OUTPUT);
pinMode(minled,OUTPUT);
Minitel.begin(1200);
// Open serial communications and wait for port to open:
Serial.begin(1200);
//while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
//}
digitalWrite(minled, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(usbled, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(minled, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(usbled, LOW); // turn the LED on (HIGH is the voltage level)
// set the data rate for the SoftwareSerial port
//Minitel.write(12); //efface l'écran; mySerial.write(12) remplace mySerial.print(12,BYTE)
// serialprint7(14); // passe en mode graphique (0x0E)
}
void serialprint7(byte b) // permet d'ecrire en 7 bits + parité sur le software serial
{ digitalWrite(usbled, LOW); // turn the LED on (HIGH is the voltage level)
boolean i = false;
for(int j = 0; j<8;j++)
{
if (bitRead(b,j)==1) i =!i; //calcul de la parité
}
if (i) bitWrite(b,7,1); //ecriture de la partié
else bitWrite(b,7,0);//ecriture de la partié
Minitel.write(b);//ecriture du byte sur le software serial
digitalWrite(usbled, HIGH); // turn the LED on (HIGH is the voltage level)
}
void printMinitel(byte b) //transmission des messages du minitel
{ digitalWrite(minled, LOW); // turn the LED on (HIGH is the voltage level)
b= bitClear(b,7); //remet à 0 le bit de parité
Serial.write(b); //écriture sur le port usb
digitalWrite(minled, HIGH); // turn the LED on (HIGH is the voltage level)
}
void printMinitelM(byte b) //transmission des messages du minitel
{ digitalWrite(minled, LOW); // turn the LED on (HIGH is the voltage level)
//b= bitClear(b,7); //remet à 0 le bit de parité
Minitel.write(b); //écriture sur le port usb
digitalWrite(minled, HIGH); // turn the LED on (HIGH is the voltage level)
}
void printMinitelsl1(byte b) //transmission des messages du minitel
{ digitalWrite(minled, LOW); // turn the LED on (HIGH is the voltage level)
//b= bitClear(b,7); //remet à 0 le bit de parité
Minitelsl1.write(b); //écriture sur le port usb
digitalWrite(minled, HIGH); // turn the LED on (HIGH is the voltage level)
}
void printMinitelsl2(byte b) //transmission des messages du minitel
{ digitalWrite(minled, LOW); // turn the LED on (HIGH is the voltage level)
//b= bitClear(b,7); //remet à 0 le bit de parité
Minitelsl2.write(b); //écriture sur le port usb
digitalWrite(minled, HIGH); // turn the LED on (HIGH is the voltage level)
}
void loop() // run over and over
{ delay (50);
if (Minitel.available())
{char c2=Minitel.read();
printMinitelM(c2);delay(20);
printMinitelsl1(c2);delay(20);
printMinitelsl2(c2);delay(20);
}
if(Minitelsl1.available())
{char c2=Minitelsl1.read();
printMinitelM(c2);}
if(Minitelsl2.available())
{char c2=Minitelsl2.read();
printMinitelM(c2);}
if (Serial.available())
serialprint7(Serial.read());
}