//Include files
#include <mc9s12c32.h>
#include "ofunc.h"
#include <stdio.h>
//MACROS DEFINITIONS
#define ENABLE_INTERRUPTS asm("cli")
//Definition of variables
short start=1, on=0;
char mensaje[]="hello world\n";
//Definition of functions
void SCItx(unsigned char SCIByte){
SCIDRL = SCIByte; /*Write data byte to SCIDRL register*/
SCICR2 |= 0x80; /*Enable TDRE interrupt*/
}
//Definition of interrupt service routines
#pragma interrupt_handler SCIhdr
extern void SCIhdr();
void SCIhdr(void){
//--------------------------Byte Transmision-------------------------------
if (SCISR1 & 0x80){
SCISR1;
SCICR2&=0x7F;
}//if (SCISR1 & 0x80)
//-----------------------End of Byte Transmision---------------------------
//--------------------------Byte Reception---------------------------------
if (SCISR1 & 0x20){ //Received data available in SCI data register
SCISR1; //Reading of SCISR1 needed to clear RDRF
if(SCIDRL=='0'){
ledoff(2);
ledon(3);
SCItx('\n');
}
if (SCIDRL=='1'){
ledoff(3);
ledon(2);
}
}//if (SCISR1 & 0x20)
//-----------------------End of Byte Reception-----------------------------
return;
}
//======================= Program´s main body ==================================
main(){
//SCI module configuration
SCIBDH=0x00; SCIBDL=0x1A; //Baud rate=19.200
SCICR1=0x00; //8 data bits & no parity
SCICR2 = 0xAC; //Enable Tx, Rx, and RDRF interrupt
SCISR1;
//Port AD pins set as general porpouse outputs
DDRAD=0xFF;
//Switch on the led connected to PAD4 (LED2)
ledon(2);
//Enable interrupts
ENABLE_INTERRUPTS;
while (1){
if (start==1){
SCItx('p');
printf("Hola\r\n");
start=0;
}
if (on==0){
ledon(1);
on=1;
}
else {
ledoff(1);
on=0;
SCItx('A');
}
delay_ms(500);
}//While(1)
}//main
THANK YOU VERY MUCH IN ADVANCE
Oroitz
#include <stdio.h>
#define _SCI
/* #include <hcs12dp256.h for S12DP256 */
#include <mc9s12c32.h>
#define TDRE 0x80
extern int _textmode;
int putchar(char c){
if (_textmode && c == '\n')
putchar('\r');
while ((SCISR1 & TDRE) == 0)
;
SCIDRL = c;
return c;
}
I'm becoming mad, do you have some operating programs in which the serial communication works? could you attach it here?
Best regards
Oroitz