![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Tools | Display Modes |
|
|
#1 (permalink) |
|
Hi,
I got this code from somewhere that writes 2 sets of hp numbers into the PIC (16f877) memory, then retrieves it and transmit them through the UART and finally is displayed on a Hyperterminal screen. This code works, but I thought that since only 8 numbers were being stored, I could reduce the starting memory address of SVC_NUM to 18 (=10+8), thinking that each character is stored using 1 byte. However, I am not sure if it is due to the fact that 8 memory spaces are not enough, or it has something to do with my transmit function, the numbers shown on the screen do not correspond to what was stored before. In fact, I tried all sorts of numbers, and the least number that I needed to have for SVC_NUM is 26 (=10+16). Hence I wondered if somehow each character needed 2 bytes instead. To test my theory, I tried reducing while(i<16) in my transmit_Num function to while (i<8), thinking that it would result in only 4 characters being displayed. But all 8 characters displayed correctly. It is only when i changed it to while(i<7), that one character was missing from the screen. So I'm not sure what's going on, and would be grateful to anyone would can help shed some light on this. //memory locations to store numbers #define ADMIN_HP_NUM 10 #define SVC_NUM 30 bank2 unsigned const char DefaultSVC[] = "96197777 "; bank2 unsigned const char Dest_Num[] = "81201378 "; void initMem() { int i=0; for (i = 0; i < 16; i++) { write2EE(ADMIN_HP_NUM + i, Dest_Num[i]); write2EE(SVC_NUM + i, DefaultSVC[i]); } } void transmit(char data) { while(!TRMT); TXREG = data; } void transmitNum(char add) //transmit hp number from memory { char temp; int i=0; while (i < 16) { temp = readEE(add + i); if (temp == NONE) break; transmit(temp); i++; } transmit('\"'); transmit(CR); } Steps in Main function: initMEM(); transmitNum(SVC_NUM); |
|
|
|
|
|
#5 (permalink) |
|
I do need at least 16 spaces. Because when I changed #define SVC_NUM to 20 instead of the current 30, my first few SVC numbers end up becoming garbage when being displayed. And hence my confusion described before. Why do I need to set aside 16 memory spaces when all I need later is just to read are 8 memory spaces?
None is defined as 0. slightly out of point here, but when we do something like this: #define None 0, is 0 an integer, binary, or char? I'm a bit confused because the string terminator is a null character '\0', but when I put temp==NULL, the error message says that the 2 operands not of the same type. Another question: My program is polling for any pressed key from the keyboard. It then stores whatever it polls into the EEPROM memory. If nothing is pressed, what is being stored in the memory? In this case, will there be a string terminator? Because I used the transmitNum function to display what was stored in the memory space onto hyperterminal and the first char displayed is always garbage, followed by 16 spaces. I was expecting it to display nothing since there is the line: if (temp == NONE) break. |
|
|
|
|
|
#6 (permalink) | |||
|
Quote:
Quote:
Quote:
Mike. |
||||
|
|
|
|
#7 (permalink) |
|
Hi, attached is my code. I modified the receive_char function such that when no key is pressed, garbage values won't be displayed. But i'm not able to receive any information through the UART.
Previously, I searched through many sample codes and coded it like what everyone does (commented out right below the current one). However, that returned garbage values when no key was pressed, and does not receive anything through the UART too. What am I doing wrong? Thank you in advance! |
|
|
|
|
|
#8 (permalink) | |
|
The only thing I can spot that is wrong is the TX pin should be set to input for the UART to work.
From the data sheet, Quote:
|
||
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Title | Starter | Forum | Replies | Latest |
| Problem to write and read from EEPROM - 16F877 | isaac82 | Micro Controllers | 7 | 27th May 2008 07:20 AM |
| 16F877 and 24LC256 I2C eeprom | spectrum | Micro Controllers | 0 | 26th November 2007 09:02 AM |
| convert int to char dspic30f | kenobe | Micro Controllers | 5 | 10th October 2007 02:21 PM |
| c++ convert argv[1] to a char array | danielsmusic | Chit-Chat | 5 | 18th March 2006 01:09 PM |
| EEPROM Memory | GatorGuy | Micro Controllers | 25 | 17th June 2005 10:02 AM |