Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interfacing pic 18f4550 with thermal printer CSN-A2

Status
Not open for further replies.

ken- R

Newbie
Newbie level 3
Joined
May 9, 2023
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
27
Hi ,
I am working on a project that aims to print medical results via a CSN-A2 thermal printer using the RS 232 serial protocol
I would like to know how to take my . for now, here is the piece of code that I was able to write :
void envoyer_text(unsigned char *t) { unsigned char i ; i = 0; while (t != 0) { Soft_UART_Write (t) ; i++; } } void main() { unsigned char titre[] = " RESULTAT DES PRISES DES PARAMETRES : "; unsigned char poids[] = " POIDS : "; unsigned char taille[] = " TAILLE : "; unsigned char imc[] = " IMC : "; unsigned char temperature[] = " TEMPERATURE : "; unsigned char spo2[] = " SPO2 : "; unsigned char pression [] = " PRESSION ARTERIELLE : "; Soft_UART_Init (PORTC, 9600, 7, 6, 0); while (1) { envoyer_text(titre); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(poids); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(taille); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(IMC); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(temperature); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(spo2); Soft_UART_Write (0x0D); Soft_UART_Write (0x0A); envoyer_text(pression);
}
}
 

Hi
i need to program thermal printer with pic 18f4550 via RS232 protocol.
is this piece of code suitable?
Code:
void envoyer_text(unsigned char *t)    
{     
unsigned char i ;     
i = 0;     
while (t != 0)        
   {           Soft_UART_Write (t)  ;           i++;         
  }     
}    
 void main()      {      
unsigned char titre[] = " RESULTAT DES PRISES DES PARAMETRES : ";        unsigned char poids[] = " POIDS : ";        unsigned char taille[] = " TAILLE : ";        unsigned char imc[] = " IMC : ";        unsigned char temperature[] = " TEMPERATURE : ";        
unsigned char spo2[] = " SPO2 : ";      unsigned char pression [] = " PRESSION ARTERIELLE : ";        
Soft_UART_Init (PORTC, 9600, 7, 6, 0);       while (1)        {              envoyer_text(titre);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(poids);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(taille);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(IMC);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(temperature);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(spo2);              Soft_UART_Write (0x0D);              Soft_UART_Write (0x0A);              envoyer_text(pression);     
}
}
 
Last edited by a moderator:

I added code tags but the code is still almost unreadable. Please format it properly so we can understand it.

Add this without the spaces or quote marks just before your code " [ CODE ] "

And add this just after your code, again without the quotes or spaces "[ /CODE ] ".

Try to put one code statement on each line, usually that is how you would write it.

Brian.
 

Seems like Soft_UART_Write() is writing a single character and envoyer_text() intended to write a string. The envoyer_text() code looks completely wrong, unless Soft_UART_Write() has some unusual capabilities. Most likely the function never returns, repeatedly outputting the string address. Need to learn about chars, strings and pointers in C to correct the code.

I'd expect something like
Code:
while (*t != 0)            
  Soft_UART_Write (*t++) ;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top