Hi,
I have a problem.I must send through the serial port the number 1 and the number 0 every second using a timer of the c167cs. Would someone know me to help?
Here is an extremely basic program that does what you ask. Perhaps this helps to get you started as you will surely need to modify it.
#include "c167cs.h" #include "intrins.h" void GPT1_viTmr3(void) interrupt 0x23 { S0TBUF = '0'; S0TBUF = '1'; /* allowed since the register is double buffered */ P2 ^= 0x0001; /* toggle P2.0 */ } void main(void) { /* setup the serial port */ S0BG = 0x0040; /* 9.600 kbaud @ 20 MHz clock */ S0CON = 0x0011; /* format: 8-N-1 */ /* P3.10 is used for TxD and P3.11 is used for RxD */ _bfld_( P3,0x0C00,0x0400); /**/ _bfld_(DP3,0x0C00,0x0400); /* set data direction */ S0CON |= 0x8000; /* enable baud rate */ /* use GPT1 for the 1 second time base */ T3CON = 0x0087; /* clock tick is 51.2 usec, count down */ T3 = 0x4C4B; /* 1 second load value */ T2CON = 0x0027; /* t2 reloads T3 on the interrupt */ T2 = 0x4C4B; T3IC = 0x004B; /* set up the interrupt level and enable it */ T3R = 1; /* start timer 3 running */ DP2 = 1; /* toggle P2.0 every second */ IEN = 1; /* globally enable interrupts */ for(;;){}; }
Hope this helps. -Chris
The code works very well and visualizes me "01" every second. As I do for making me visualize before "0", after a second "1", after another second "0", after another second "1" ..... etc. Must I put another timer? What must I change in the list? Thanks as for the help.
If I were to do it, I could imagine that you would use a counter (volatile variable) that checks if it is even or odd. If even you send a '0' and when it is odd you send a '1'. This logic (code) would be placed in the interrupt that already exists for the one second.
"...I will try it to the university..."
Is this a homework assignment that you should be doing yourself...?
In practice I must bring my thesis stand-alone using this microcontroller and the prof has told me to begin with this application.
View all questions in Keil forum