Simulazione esame.

Piattafora Micro-GT I.D.E.

Programmazione PIC in C16.

Distributore automatico "Caffettiera".

Classe terza elettrotecnici 2009/2010

22 Aprile 2010

Simulazione d’esame  Elettronica:Programmazione e progettazione sistemi a Microprocessori.

 

Cognome …………………………………………Nome…………………………………………

 

Si consideri il pannello comandi serigrafato disegnato qui sopra. Si produca e si compili un programma in C per PIC 16F877A, da riportare sul retro del foglio diviso in due colonne, che gestisca almeno i pulsanti di selezione caffè, cappuccino, the, che richiamino le tre funzioni omonime. Come verifica del fatto che si è entrati nella procedura di selezione si accendano rispettivamente RB0,RB1,RB2. Un canale analogico mostra la temperatura interna dell'acqua nel display LCD.

Inviare il progetto MpLab a prof.gottardo@tiscali.it dopo averlo impaccato con l’apposito tasto presente sul software della Microchip.

Tempo a disposizione 1 ora.

-------------------------------------------------------------------------

Collegamento dell'Hardware

Nell'immagine riporto il collegamento del display LCD (due righe per 16 caratteri) pilotato in modalità 8 bit.

 

download dello schema elettrico manoscritto

Al PORT B dovranno essere collegati i pulsanti di comando tramite resistenze di PULL down, ovvero all'azione premuto corrisponde un uno logico.

(Volutamente il disegno elettrico sovrastante non è completo così che possa ancora essere utilizzabile come esercitazione in classe).

 

---------------------------------------------------------------------------

bozza della soluzione:

//(Volutamente il sorgente non è completo, e riferito correttamente alla pulsantiera così che possa ancora essere utilizzabile come

 //esercitazione in classe).

/*********************************************
*                      Prof. Gottardo Marco                               *
*                  simulazione d'esame di qualifica                      *
*                     anno formativo 2009/2010                          *

*                          revisione 12/07/2012                             *
*            distributore automatico di bevande calde               *
*   piattaforma Micro-GT IDE PIC  16F877A caffettiera.c *
*********************************************/


#include<pic.h>
#include"Delay.h"
#include<math.h>
// #include<stdlib.h>
#include<stdio.h>

#define EN RE0
#define RW RE1
#define RS RE2

#define temperature RA0
#define votage_ref RA3

//sugar quantity device setting in binary (3 bits)
#define dispencer_b0 RA2
#define dispencer_b1 RA4
#define dispencer_b2 RA5

#define coffee_solenoid RB7 //PORT B tutti ingressi
#define milk_solenoid RB6
#define remainder RB5
#define tea RB4
#define cappuccino RB3
#define coffee RB2
#define sugar_minus RB1
#define sugar_plus RB0

#define sugar_level1 RC0 //PORT C sugar bargraph LED 1
#define sugar_level2 RC1 //PORT C sugar bargraph LED 2
#define sugar_level3 RC2 //PORT C sugar bargraph LED 3
#define sugar_level4 RC3 //PORT C sugar bargraph LED 4
#define sugar_level5 RC4 //PORT C sugar bargraph LED 5
#define sugar_level6 RC5 //PORT C sugar bargraph LED 6
#define sugar_level7 RC6 //PORT C sugar bargraph LED 7

#define sugar_present RC7 //PORT C sugar bargraph LED 8

// ho dichiarato la mia float to string
char * myftoa(float fl, int * sts);

void CLOCK();
void CLEAR();
void CONFIGURA();
void INIZIALIZZA();
void splash();
void VAI(unsigned char r, unsigned char c);
void SCRIVI(char lettera);
void FRASE(unsigned char l, unsigned char n, const char* msg1);
void CONVERSIONE();

void main(){
CONFIGURA();
INIZIALIZZA();
CLEAR();
DelayMs(10);
splash();
while(1){

//CONVERSIONE();

if (coffee==0){
CLEAR();
DelayMs(10);
FRASE(1,1,"selezione");
FRASE(2,1,"caffe");
}
if (cappuccino==0){
CLEAR();
DelayMs(10);
FRASE(1,1,"selezione");
FRASE(2,1,"cappuccino");
}
DelayMs(10);
}
}


void CLEAR(){RS=0; RW=0;
//PORTD=0x0F;
PORTD=0x01;
CLOCK();
DelayMs(2);
}

void CLOCK(){EN=1;
DelayMs(1);
EN=0;
}

void CONFIGURA(){
TRISB=0b11111111;
TRISC=0b1111;//primo nibble ingressi, lascio libera la seriale
TRISD=0;
TRISE=0;
PORTD=0;
PORTE=0;
OPTION=0x80;
ADCON1=0x02;
}

void INIZIALIZZA(){RS=0; RW=0; PORTD=0x30;
DelayMs(15);
CLOCK();
DelayMs(10);
CLOCK();
DelayMs(10);
CLOCK();
DelayMs(10);
RS=0; RW=0; PORTD=0x38;
CLOCK();
DelayMs(1);
RS=0; RW=0; PORTD=0x08;
CLOCK();
DelayMs(1);
RS=0; RW=0; PORTD=0x0C;
CLOCK();
DelayMs(1);
RS=0; RW=0; PORTD=0x01;
CLOCK();
DelayMs(1);
RS=0; RW=0; PORTD=0x03;
CLOCK();
DelayMs(1);
}

void SCRIVI(char lettera){RS=1; RW=0; PORTD=(lettera);
CLOCK();
DelayUs(50);
}
void VAI(unsigned char r, unsigned char c){unsigned char a=0;
RS=0; RW=0;
if(r==1){a=c+127;}
if(r==2){a=c+191;}
PORTD=(a);
CLOCK();
DelayUs(50);}
void FRASE(unsigned char l, unsigned char n, const char* msg1){
while(n<=16){VAI(l,n);
SCRIVI(*msg1++);
n++;
}
n=1;
}

void splash(){//scrive su LCD la presentazione per alcuni secondi
FRASE(1,1," Gottardo Marco ");
FRASE(2,1,"G-Tronic Robotic");
DelayS(2);
CLEAR();
DelayMs(2);

};

void CONVERSIONE()
{
unsigned int myaddress = 0;
unsigned int * sttus;
char * mybuf;
char thechar;
float ain = 0;



TRISA=1;
ADCON0=0b11000001;
ADCON1=0b10000010;
ADGO=1;
while(ADGO){}

// memorizzo la parte alta dell'indirizzo
myaddress= ADRESH;
// mi recupero il valore calcolato nella varibile float
ain = ((myaddress*256)+ADRESL)*4,887;
// a questo punto abbiamo il float da visualizzare

mybuf = myftoa(ain, &sttus);
int y = 1;
while (thechar = *mybuf++)
{
VAI(2,y);
SCRIVI(thechar);
y++;
}
}


char * myftoa(float f, int * status)
{
static char buf[17];
char * cp = buf;
unsigned long l, rem;

if(f < 0) {
*cp++ = '-';
f = -f;
}
l = (unsigned long)f;
f -= (float)l;
rem = (unsigned long)(f * 1e6);
sprintf(cp, "%lu.%6.6lu", l, rem);
return buf;
}
 

-------------------------------------bozza del file settaggi.h-----------------------------

 __CONFIG (HS & WDTDIS & PWRTDIS & BORDIS & LVPDIS
& DUNPROT & WRTEN & DEBUGDIS & UNPROTECT);

#define XTAL_FREQ 20MHZ //calibtare frequency oscillator

void settaggi(){
TRISB=0; //PORTB as output
TRISC=0; //PORTC as output
}

------------------------------------------------------------------------------------------
 

download progetto zippato per PIC16F877A file coffee_machine per Micro-GT IDE

  Pagina precedente