// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 10, 4, 5, 6, 7); // bib init (initialisation)
//////////////////////////////////////////////////////////////////////////
void setup() {
// un masque pour chaque bit de DDRD correspond au DATA
DDRD |= 0x80; // PD 7 en sortie
DDRD |= 0x40; // PD 6 en sortie
DDRD |= 0x20; // PD 5 en sortie
DDRD |= 0x10; // PD 4 en sortie
// un masque pour chaque bit de DDRB correspond au RS et E:
DDRB |= 0x01;// PB0 en sortie RS: signal pour afficher les DATA
DDRB |= 0x04;// PB2 en sortie E: autorisation de l'afficher des DATA
// config timer
TCCR1A = 0x00 ;
TCCR1B = 0x05 ; // le cs cest un diviseur de frequence
//////////////////////////////////////////////////////////////////////////
//lcd.begin(16, 2); // bib init (initialisation)
//initialisation();
Affichage();
}
//////////////////////////////////////////////////////////////////////////
void loop() {
}
//////////////////////////////////////////////////////////////////////////
void Affichage() { // affichage de chaine de caractères
unsigned char lettre[16] = "Projet-afficheur";
unsigned char lettre1[16] = "30 Novembre 2022";
decalage_ligne_colon(0x80);
for (int i = 0; i<strlen(lettre);i++){
uint8_t value = lettre[i];
PORTB |= 0x01; // mise a 1 de RS: PB0
PORTD = value; // upper 4 bit ascii
pulse();
PORTD = PORTD << 4;// lower 4bit ascii
pulse();
}
decalage_ligne_colon(0xC0);
for (int j = 0; j<strlen(lettre1);j++){
uint8_t value1 = lettre1[j];
PORTB |= 0x01; // mise a 1 de RS: PB0
PORTD = value1; // upper 4 bit ascii
pulse();
PORTD = PORTD << 4;// lower 4bit ascii
pulse();
}
}
//////////////////////////////////////////////////////////////////////////
void time_ms(){ //fonction pour la temporistation
TIM16_WriteTCNT1( 0x00 );
while(TIM16_ReadTCNT1() < 0x00AF)
{
asm("nop");
}
}
//////////////////////////////////////////////////////////////////////////
void pulse(){
PORTB &=~ 0x04; // mise a 0 de E: PB2
PORTB |= 0x04; // mise a 1 de E: PB2
PORTB &=~ 0x04; // mise a 0 de E: PB2
time_ms();
}
//////////////////////////////////////////////////////////////////////////
void decalage_ligne_colon(uint8_t decal){
PORTB &=~ 0x01;
// PORTD = 0x80 | 0x04; 1000 0000|row
//uint8_t decal = 0x80; // 0xC0: ecrir a ligen 2 //0x84 : declage de 4 dans l'afficheur
PORTD = decal; // upper 4 bit ascii
pulse();
PORTD = PORTD << 4;// lower 4bit ascii
// PORTD = 0x80; // lower 4bit ascii
//delayMicroseconds(1000); // enable pulse must be >450ns
time_ms();
pulse();
//delayMicroseconds(100); // commands need > 37us to settle.
time_ms();
}
//////////////////////////////////////////////////////////////////////////
void TIM16_WriteTCNT1( unsigned int i ) // permet d'ecrire dans le timer 1///// TIM16_WriteTCNT1( 0x2326 );
{
unsigned char sreg;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
cli();
/* Set TCNT1 to i */
TCNT1 = i;
/* Restore global interrupt flag */
SREG = sreg;
}
//////////////////////////////////////////////////////////////////////////
unsigned int TIM16_ReadTCNT1( void ) //permet de lire la valeur du timer 1
{
unsigned char sreg;
unsigned int i;
/* Save global interrupt flag */
sreg = SREG;
/* Disable interrupts */
cli(); // permet le processeur de ne pas s'arret a cause d'un evenement exterieur
/* Read TCNT1 into i */
i = TCNT1;
/* Restore global interrupt flag */
SREG = sreg;
return i;
}
////////////////////////////////////////////////////////////////////////
void EP(void){
PORTB &=~ 0x04; // mise a 0 de E: PB2
PORTB |= 0x04; // mise a 1 de E: PB2
PORTB &=~ 0x04; // mise a 0 de E: PB2
}
////////////////////////////////////////////////////////////////////////
void initialisation(){ // //lcd.begin(16, 2); // bib init (initialisation)
//page 6 doc
delay(15);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x03;
EP();
delay(5);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x03;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x03;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x02;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x02;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0xC0;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x00;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x80;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x00;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x10;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x00;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x60;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x00;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x04;
EP();
delayMicroseconds(100);
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x00;
EP();
PORTB &=~ 0x01;
PORTD &=~ 0xF0;
PORTD |= 0x02;
EP();
}
//////////////////////////////////////////////////////////////////////////
// void retour_ligne(){
// PORTB &=~ 0x01;
// uint8_t decal = 0xC0; // 0xC0: ecrir a ligen 2 //0x84 : declage de 4 dans l'afficheur
// PORTD = decal; // upper 4 bit ascii
// pulse();
// PORTD = PORTD << 4;// lower 4bit ascii
// // PORTD = 0x80; // lower 4bit ascii
// //delayMicroseconds(1000); // enable pulse must be >450ns
// time_ms();
// pulse();
// //delayMicroseconds(100); // commands need > 37us to settle.
// }