??? 02/04/06 20:32 Modified: 02/04/06 22:20 Read: times |
#109193 - c programing question |
Hi, it´s me once more, with my c programming questions.
I made a program that echoes any input using the serial interruption and thanks god (and your help) its finally working OK. My question is: If I now try to make a printf, putchar, nothing happens. I think this might be because it enters the interrupt function before outputing the message. here is the code: <pre> /*------------------------------------------------ includes ------------------------------------------------*/ #include <stdio.h> #include <reg52.h> /*------------------------------------------------ declarations ------------------------------------------------*/ #define XTAL 11059200 /*------------------------------------------------ declarations ------------------------------------------------*/ void serialini (int baud); void serialint (void); /*------------------------------------------------ The main C function. Program execution starts here after stack initialization. ------------------------------------------------*/ void main (void) { serialini(19200); /* Inicialize serial: baudrate = 9600 */ printf ("hola\n"); while(1); /* infinite loop */ } /*------------------------------------------------ Setup the serial port for 9600 baud at 11.0592MHz. ------------------------------------------------*/ void serialini (int baud){ EA = 0; /* disable interruptions */ PCON |= 0x80; /* PCON: double baudrate */ SCON = 0x50; /* SCON: mode 1 8-bit UART, enable rcvr */ TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */ TH1 = 256-((XTAL/192)/baud); /* TH1: reload value */ ES = 1; /* ES: enable serial int. */ TR1 = 1; /* TR1: timer 1 run */ TI = 0; RI = 0; EA = 1; /* enable interruptions */ } /*------------------------------------------------ Serial interruption, echos the incoming byte ------------------------------------------------*/ void serialint (void) interrupt 4 using 2 { /*------------------------------------------------ Received data interrupt. ------------------------------------------------*/ char c; if (RI != 0){ RI = 0; c = SBUF; SBUF = c; } /*------------------------------------------------ Transmitted data interrupt. ------------------------------------------------*/ if (TI != 0){ TI = 0; } } <\pre> |
Topic | Author | Date |
c programing question | 01/01/70 00:00 | |
How to post your code | 01/01/70 00:00 | |
re: How to post your code | 01/01/70 00:00 | |
That'll be it, then! | 01/01/70 00:00 | |
putchar uses polled IO | 01/01/70 00:00 | |
Polled means...... | 01/01/70 00:00 | |
See for yourself!![]() | 01/01/70 00:00 | |
How are you debuging? | 01/01/70 00:00 | |
RE: How are you debuging? | 01/01/70 00:00 | |
project | 01/01/70 00:00 | |
Start a new thread | 01/01/70 00:00 |