yueying_53
New Member
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);
write2EE(SVC_NUM + i, DefaultSVC);
}
}
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);
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);
write2EE(SVC_NUM + i, DefaultSVC);
}
}
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);