Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
for(char t=0;t<5;t++) {
ch=c[t];
HSerout(ch); //sending back the data
}
HSerout(c[0]);
HSerout(c[1]);
HSerout(c[2]);
HSerout(c[3]);
HSerout(c[4]);
I added comments to the code:
Code:char *temp; // Temporary pointer that we will use inside the loop. temp = c; // Set the pointer at the beginning for(char t=0;t<5;t++) { ch=*temp++; // Increment the pointer and get the character from that position HSerout(ch); //sending back the data }
This is not working................
not sending string back....Code:for(char t=0;t<6;t++){ *c++= HSerin(); } c = c-5; for(char t=0;t<5;t++) { ch=*c++; HSerout(ch); //sending back the data }
for(char t=0;t<5;t++) {
ch=c[t];
HSerout(ch); //sending back the data
}
for(char t=0;t<5;t++) {
HSerout(c[t]); //sending back the data
}
ch='a';
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
*c++= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
char *temp; // Temporary pointer that we will use inside the loop.
temp = c; // Set the pointer at the beginning
for(char t=0;t<5;t++) {
c=*temp++; // Increment the pointer and get the character from that position
ch=c;
HSerout(ch); //sending back the data
}
ch='a';
char *temp; // Temporary pointer that we will use inside the loop.
temp = c; // Set the pointer at the beginning
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
*temp++= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
temp = c; // Set the pointer at the beginning
for(char t=0;t<5;t++) {
c=*temp++; // Increment the pointer and get the character from that position
ch=c;
HSerout(ch); //sending back the data
}
ch='a';
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
c[t]= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
for(char t=0;t<5;t++) {
HSerout(c[t]); //sending back the data
}
Your original motivation was to save memory.. but can you now see how using pointers only makes things more complicated (in this case) and uses more memory than the "elegant" way:
not working.. I agree with that.
ch='a';
char *temp; // Temporary pointer that we will use inside the loop.
temp = c; // Set the pointer at the beginning
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
*temp++= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
#include <htc.h>
__CONFIG(LVP_OFF & BOREN_OFF & PWRTE_ON & WDTE_OFF & FOSC_HS);
#define _XTAL_FREQ 20000000
unsigned char *c;
unsigned char HSerin(void);
void HSerout(unsigned char ch),
HSerinit(void);
void main(void) // program entry
{
TRISB=0x00;
unsigned char ch ; // <- LOOK HERE.
ADCON1 = 0x6; // Analogue off
HSerinit();
__delay_ms(1);
while(1) // endless Loop
{
ch='a';
char *temp; // Temporary pointer that we will use inside the loop.
temp = c; // Set the pointer at the beginning
HSerout(ch); //for testing UART initially
for(char t=0;t<5;t++){
*temp++= HSerin();
}
ch='b';//testing after saving...
HSerout(ch);
}
}
void HSerinit()
{
TRISC = 0b10000000; // should ideally be set
SPBRG = 129; // 20Mhz xtal 9600 BAUD
TXSTA = 0x24; // TXEN and BRGH
RCSTA = 0x90; // SPEN and CREN
}
void HSerout(unsigned char ch) {
while(!TXIF); // Wait for module to finish
TXREG = ch; // ready to send
}
unsigned char HSerin()
{ while(!RCIF); // Wait for a character
return RCREG; // return character
}
Is the "HSerin();" function blocking or unblocking function?
.. that is a thinker for you.
after reading and doing some experiment with code i think it is blocking function because code execution is not coming out of function, don't know why??