File "debug._c"
Full Path: /home/analogde/www/private/Projet/debug/debug._c
File size: 5.68 KB
MIME-type: text/x-c
Charset: 8 bit
#include "HC12.H"
int Mille,Centaine,Dizaine,Unite;
int val;
unsigned int canal[8];
char ascii[8];
/**************************************************************************/
void init_SCI(unsigned int baud)
{
asm(" SEI");
SCICR1 = 0x00; /* 0 0 0 0 0 0 0 0 /* 8bits et pas de parit */
/* | | | | | | | |
| | | | | | | \____ Even Parity
| | | | | | \______ Parity Disabled
| | | | | \________ Short IDLE line mode (not used)
| | | | \__________ Wakeup by IDLE line rec (not used)
| | | \____________ 8 data bits
| | \______________ Not used (loopback disabled)
| \________________ SCI1 enabled in wait mode
\__________________ Normal (not loopback) mode
*/
SCICR2 = 0x2C; /* 0 0 1 0 1 1 0 0 /* TX et RX actif + RX int*/
/* | | | | | | | |
| | | | | | | \____ No Break
| | | | | | \______ Not in wakeup mode (always awake)
| | | | | \________ Reciever enabled
| | | | \__________ Transmitter disabled
| | | \____________ No IDLE Interrupt
| | \______________ Reciever Interrupts used
| \________________ No Tranmit Complete Interrupt
\__________________ No Tranmit Ready Interrupt
*/
SCIBDH = 0x00;
SCIBDL = 0x34; // 9600 bauds (52 en dcimal)
asm(" CLI");
}
/**************************************************************************/
void initialise_SCI(void)
{
SCIBDH = 0x34; // 9600bps @ 8MHz Mclk
SCIBDL = 0x00;
SCICR1 = 0x00; // mode normal 8bits
SCICR2 = 0x0C; // pas d'interruption, pas de parit
}
/**************************************************************************/
void init_ADC(void)
{
ATDCTL2 = 0xC0; /* dmarrage ADC */
ATDCTL3 = 0x00; /* cycle de 8 conversions */
ATDCTL4 = 0x75; /* mode 10 bits */
ATDCTL5 = 0x90; /* 1 0 0 1 0 0 0 0
| | | | \__/
| | | | |
| | | | \___ First channel = 2
| | | \________ MULT = 1 => multiple channels
| | \__________ SCAN = 0 => one set of conversions
| \____________ DSGN = 0 => unsigned
\______________ DJM = 1 => right justified
*/
}
/**********************************************************/
void ecrire_data(char data)
{
int i;
i= 0x55;
return;
}
/**********************************************************/
void ecrire_chaine(char *buffer)
{
while(*buffer)
{ ecrire_data(*buffer);
buffer++;
}
return;
}
/**********************************************************/
void conversion_decimal(void)
{
int compare;
Mille = 0;
Centaine = 0;
Dizaine = 0;
Unite = 0;
// recherche du nombre en dcimal - 4 chiffres
compare=val;
while( compare > 1000 ) // nombre de paquets de 1000
{ Mille++;
compare=compare-1000;
}
while( compare > 100 ) // nombre de centaines
{ Centaine++;
compare=compare-100;
}
while( compare > 10 ) // nombre de dizaines
{ Dizaine++;
compare=compare-10;
}
Unite=compare;
}
/**********************************************************/
void conversion_Ascii(void)
{
ascii[0]=Mille+0x30;
ascii[1]='.'; // affiche virgule
ascii[2]=Centaine+0x30; // centaines de mV
ascii[3]=Dizaine+0x30; // dizaines de mV
ascii[4]=Unite+0x30; // affiche les mV
ascii[5]='V'; // affiche le V de Volt
}
/**********************************************************/
void acquisition(void)
{
ATDCTL5 = 0x90; // lance la conversion
while ((ADSTAT0 & 0x80) == 0 ) ; /* attendre la fin de la conversion */
canal[0] = ADR0;
canal[1] = ADR1;
canal[2] = ADR2;
canal[3] = ADR3;
canal[4] = ADR4;
canal[5] = ADR5;
canal[6] = ADR6;
canal[7] = ADR7;
}
/**************************************************************************/
void traitement(void)
{
// lire le rsultat + stockage
canal[6]= ADR6;
val= (ADR6 * 4888)/10000;
}
/**************************************************************************/
void envoi_caractere(char c)
{
while( (SCISR1 & 0x80 )== 0 ); // attendre la monte du flag TDRE
SCIDRL = c;
}
/**********************************************************/
void envoi_chaine(char str[])
{
char *ptr;
for(ptr = str; *ptr != '\0' ; ptr++ )
{ envoi_caractere(*ptr);
}
}
/**************************************************************************/
void transmettre_CRLF(void)
{
SCIDRL = 0x0A; // fin de ligne = end of line
while ( (SCISR1 & 0x80) == 0) ; // attendre le flag TDRE
SCIDRL = 0x0D; // retour la ligne = line feed
while ( (SCISR1 & 0x80) == 0) ; // attendre le flag TDRE
}
/**************************************************************************/
void main(void)
{
/*char buffer[10]="";
char v;
char *ptr;
buffer[0]='A';
buffer[1]='b';
buffer[2]='c';
buffer[3]='d';
v=buffer[2];
p=ascii;
ecrire_chaine(p);*/
char *ptr;
COPCTL=0x00;
init_ADC();
init_SCI(9600);
while(1)
{ transmettre_CRLF();
acquisition();
traitement();
conversion_decimal();
conversion_Ascii();
ptr=ascii;
envoi_chaine(ptr);
}
}
/**************************************************************************/