Diferencia entre revisiones de «Código Acelerómetro para Codewarrior 10.6»
De Wikitronica
Línea 53: | Línea 53: | ||
'''Enviar y recibir caracteres''' | '''Enviar y recibir caracteres''' | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
− | + | char RecChar(void) { | |
byte rec_char; | byte rec_char; | ||
Línea 64: | Línea 64: | ||
return (char) SCI1D; | return (char) SCI1D; | ||
} | } | ||
− | </syntaxhighlight>< | + | </syntaxhighlight> |
+ | |||
+ | |||
+ | <syntaxhighlight lang="c"> | ||
+ | void SendChar(char s_char) { | ||
+ | |||
+ | SCI1C2 = 0x08; // enable Tx | ||
+ | while(!SCI1S1_TDRE){ } | ||
+ | SCI1D = (byte) s_char; // 2nd half of TDRE clear procedure | ||
+ | } //end SendChar | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | '''Enviar mensaje''' | ||
+ | <syntaxhighlight lang="c"> | ||
+ | void SendMsg(char msg[]) { | ||
+ | byte i=0; | ||
+ | char nxt_char; | ||
+ | |||
+ | SCI1C2 = 0x08; // enable Tx | ||
+ | nxt_char = msg[i++]; | ||
+ | while(nxt_char != 0x00) { | ||
+ | while(!SCI1S1_TDRE){} | ||
+ | SCI1D = (byte) nxt_char; // 2nd half of TDRE clear procedure | ||
+ | nxt_char = msg[i++]; | ||
+ | } //end while((SCI1D | ||
+ | } //end SendMsg | ||
+ | |||
+ | </syntaxhighlight> |
Revisión del 15:46 22 jun 2016
Código del Acelerómetro en CodeWarrior 10.6
Descripción de funciones
Inicialización de periféricos ICS
void ICS_FEI(void) {
if (NVICSTRM != 0xFF)
ICSTRM = NVICSTRM;
else
ICSTRM = 0xAD;
ICSC1 = ICSC1_FEI;
ICSC2 = ICSC2_FEI;
ICSSC = ICSSC_FEI;
while (ICSC1_CLKS != ICSSC_CLKST) {}
} //end
KBI
void InitKBI(void) {
// Enable KBI1P[3:2] as interrupt
KBI1PE = KBI_SW;
KBI1SC = 0b00000110;
/* ||||
|||+---- KBIMOD = KBI detection mode: 0=edge only
||+----- KBIE = KBI int enable: 1=enabled
|+------ KBACK = KBI int acknowledge: 1=clr IRQF
+------- KBF = KBI flag
*/
}
SCI
void InitSCI(word baud) {
SCI1BD = baud; // set baud
}
Funciones para la transmisión y recepción de datos
Enviar y recibir caracteres
char RecChar(void) {
byte rec_char;
if (SCI1S1_RDRF)
rec_char = SCI1D;
SCI1C2_RE = 1;
while(!SCI1S1_RDRF){ };
rec_char = SCI1D;
SendChar((char) rec_char);
return (char) SCI1D;
}
void SendChar(char s_char) {
SCI1C2 = 0x08; // enable Tx
while(!SCI1S1_TDRE){ }
SCI1D = (byte) s_char; // 2nd half of TDRE clear procedure
} //end SendChar
}
Enviar mensaje
void SendMsg(char msg[]) {
byte i=0;
char nxt_char;
SCI1C2 = 0x08; // enable Tx
nxt_char = msg[i++];
while(nxt_char != 0x00) {
while(!SCI1S1_TDRE){}
SCI1D = (byte) nxt_char; // 2nd half of TDRE clear procedure
nxt_char = msg[i++];
} //end while((SCI1D
} //end SendMsg