We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi I have been trying this code using uVision emulator and it works fine, then I download it to the Infineon C167CR-L and again works fine using Monitor. I stop debugging and connect the serial port to my PC using Hyper Terminal and works fine also but when I reset the unit or I just switch off the power supply, it doesn't work right anymore. The screen on HT (Hyper Terminal) starts to display a lot of spaces, ooooos or smiles but the program doesn't work as it did using Monitor. Any advice on this?
/*----------------------------------------------------- Define Port 7, Direction Register, and Open Drain Register. ------------------------------------------------------*/ #include <stdio.h> /* standard I/O .h-file */ #include <reg167.h> /* special function register 80C167 */ char cmd; /* Store value received from port 3 here */ /*------------------------------------------------------------ MAIN C Function --------------------------------------------------------*/ void main (void) { /*---------------------- Configure P2.15-P2.12 as Outputs. ---------------------------*/ DP2 = 0xF000; /* Configure P2.15-P7.12 for output, */ ODP2 = 0xF000; /* Setup P2.15-P2.12 for open-drain */ /* initialize the serial interface */ #ifndef MCB167 /* do not initialize if you use Monitor-166 */ P3 |= 0x0400; /* SET PORT 3.10 OUTPUT LATCH (TXD) */ DP3 |= 0x0400; /* SET PORT 3.10 DIRECTION CONTROL (TXD OUTPUT) */ DP3 &= 0xF7FF; /* RESET PORT 3.11 DIRECTION CONTROL (RXD INPUT) */ S0TIC = 0x80; /* SET TRANSMIT INTERRUPT FLAG */ S0RIC = 0x00; /* DELETE RECEIVE INTERRUPT FLAG */ S0BG = 0x40; /* SET BAUDRATE TO 9600 BAUD */ S0CON = 0x8011; /* SET SERIAL MODE */ #endif /*-------------------------------------- -------------------------*/ printf ("Robot ready to receive commands "); while (1) /* An embedded program never stops and returns */ { /* Here is an endless loop to solve this and */ /* monitor serial port */ scanf ("%c", &cmd); printf ("%c\n", cmd); /* Check for direction robot */ switch(cmd) { case '8' : P2 = 0x0000; break; case '2' : P2 = 0x5000; break; case '4' : P2 = 0x4000; break; case '6' : P2 = 0x1000; break; default : P2 = 0xA000;; } } }