0% found this document useful (0 votes)
3 views

Code

nothing

Uploaded by

Rinchi Jihed
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Code

nothing

Uploaded by

Rinchi Jihed
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

sbit LCD_RS at RD0_bit;

sbit LCD_EN at RD1_bit;


sbit LCD_D4 at RD2_bit;
sbit LCD_D5 at RD3_bit;
sbit LCD_D6 at RD4_bit;
sbit LCD_D7 at RD5_bit;

sbit LCD_RS_Direction at TRISD0_bit;


sbit LCD_EN_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD4_bit;
sbit LCD_D7_Direction at TRISD5_bit;

char segmentValue[] = {
0x3F, 0x06, 0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

void LED_Blink();
void LED_GreenBlink();
void ADC_ReadDisplay();
void display(char digit, char value);
void DispA();
void DispB();

char countA = 0;
char countB = 0;

int declanche = 0;int nbrPannes = 0;char panne[10];


void interrupt() {
if(INTCON.INTF == 1) {
RB3_bit = 1;
delay_ms(20);
nbrPannes++;
INTCON.INTF = 0 ;
declanche = 1;
}
if (INTCON.RBIF) {
if (PORTB.F5 == 1) {
LED_Blink();
}
if (PORTB.F4 == 1) {
LED_GreenBlink();
}
if (PORTB.F6 == 1 ) {
countA++;
if (countA > 50) {
countA = 0;
}
DispA();
delay_ms(500);

} else if (PORTB.F6 == 0) {

}
if (PORTB.F7 == 1 ) {
countB++;
if (countB > 20) {
countB = 0;
}
DispB();
delay_ms(500);

} else if (PORTB.F7 == 0) {

INTCON.RBIF = 0;
}
}

void main() {

INTCON.GIE = 1;

INTCON.RBIE = 1;
INTCON.INTE = 1;
INTCON.INTF = 0;
INTCON.RBIF = 0;

TRISB.F0 = 1;
TRISB.F4 = 1;
TRISB.F5 = 1;
TRISB.F6 = 1;
TRISB.F3 = 0;
TRISB.F7 = 1;
TRISB.F1 = 1;
TRISB2_bit = 1;
TRISE.F0 = 1;
TRISA.F5 = 1; TRISA.F0 = 0; TRISA.F1 = 0; TRISA.F2 = 1; TRISA.F3 = 0; TRISA.F4
= 0;

TRISD = 0x00;
TRISC = 0x00;
RA3_bit = 0;
RA4_bit = 0;
RA0_bit = 0;
RA1_bit = 0;

Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1, 1, "Gestion ");
Lcd_Out(2, 1, "Qualite_Emballag");
RB3_bit = 0;
RE1_bit = 0;

while (1) {
EEPROM_Write(0x32,nbrPannes);

if (ADC_Read(2) > 512 ) {


ADC_ReadDisplay();
Lcd_Cmd(_LCD_CLEAR);
RA3_bit = 1;
while( ADC_Read(6) > 512){
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2, 4, "STOP");
delay_ms(200);
RA0_bit = 0;
RA1_bit = 0;
RA3_bit = 0;}

if(declanche == 1) {
declanche = 0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(2, 5, "EN PANNE");
delay_ms(2000);
RB3_bit = 0;}

if( RB2_bit == 1) {countA = 0;


countB = 0;
delay_ms(20);}

if(RB1_bit == 1){
IntToStr(EEPROM_Read(0x32),panne);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "nbr pannes : ");
Lcd_Out(4, 1,panne);
delay_ms(3000);
Lcd_Cmd(_LCD_CLEAR);

}
} else {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 1, "Gestion ");
Lcd_Out(2, 1, "Qualite_Emballag");
delay_ms(500);
RA0_bit = 0;
RA1_bit = 0;
RA3_bit = 0;

void LED_Blink() {
int i;
for (i = 0; i < 4; i++) {
PORTA.F0 = 1;
Delay_ms(500);
PORTA.F0 = 0;
Delay_ms(500);
}
}

void LED_GreenBlink() {
int i;
for (i = 0; i < 4; i++) {
PORTA.F1 = 1;
Delay_ms(500);
PORTA.F1 = 0;
Delay_ms(500);
}
}

void ADC_ReadDisplay() {
int read_poid;
read_poid = ADC_Read(5);
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1, 4, "START ");
Lcd_Out(2, 1, "Qualite_P : ");

if (read_poid <= 575) {


Lcd_Out(3, 1, "Satisfaisante");
} else {
Lcd_Out(3, 1, "Insatisf");
}
delay_ms(500);
}

void display(char digit, char value) {


PORTC = segmentValue[value];
if (digit == 1) {
RD6_bit = 1;
RD7_bit = 0;
} else if (digit == 2) {
RD6_bit = 0;
RD7_bit = 1;
}
}

void DispA() {
char digitA1 = countA / 10;
char digitA2 = countA % 10;

display(1, digitA1);
Delay_ms(300);
display(2, digitA2);
Delay_ms(500);

}
void DispB() {

char digitB1 = countB / 10;


char digitB2 = countB % 10;

display(1, digitB1);
Delay_ms(300);
display(2, digitB2);
Delay_ms(500);
}

You might also like