CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Printing from Pc serial port to parallel port printer

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
oyhan



Joined: 03 Jun 2005
Posts: 21
Location: TURKEY

View user's profile Send private message Send e-mail MSN Messenger

Printing from Pc serial port to parallel port printer
PostPosted: Sun Nov 30, 2008 7:50 am     Reply with quote

Hi
I want to write some character from pc serial port to parallel printer. Mini Thermal Printer has 24 colon and parallel port.
While printer is writing I saw some problem. Printer is not write some data specially after 48th character.
I use hardware flow control that is rs232 DSR pin. While printer buffer is full I want to stop Pc data transmit after printer buffer is emptied.
What is my problem ? Would you help me please for that.
Best Regards...
Code:

#include <18F452.h>
//#device adc=10
#fuses HS, NOWDT, NOPROTECT, NOCPD, NOBROWNOUT, NOWRTD, PUT, NOLVP
#use delay(clock=20000000)
#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, bits=8, ERRORS)

#byte    PORTA  = 0x0F80
#byte    PORTB  = 0x0F81
#byte    PORTC  = 0x0F82
#byte    PORTD  = 0x0F83
#byte    PORTE  = 0x0F84
#bit     STROBE = PORTA.0  //for paralelle port printer busy_pin output 
#bit     BUSY   = PORTA.1  //for paralelle port printer busy_pin input
#bit     DSR    = PORTC.2  //for rs232 hardware flow control

#byte RCREG = 0x0FAE
#byte RCSTA = 0x0FAB
#bit RCIF = RCREG.5
#bit OERR = RCSTA.1
#bit CREN = RCSTA.4
 
#define LF ('\n')
#define CR (0xD)

char b;
int1  rcvd_uart = 0;

#int_RDA
void  RDA_isr(void)
{
   DSR=1;  // Data Set Ready is passive
   b=RCREG;
   rcvd_uart = 1;
}
void main()
{  setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF);
   setup_spi(FALSE);   setup_psp(PSP_DISABLED);  setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_OFF); setup_oscillator(False);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   SET_TRIS_A( 0b10000010 ); SET_TRIS_D( 0x00 ); SET_TRIS_C( 0b10001011 ); SET_TRIS_E( 0b11111 );
   PORTD=0x00; 
   STROBE=1;
   DSR=0;  // Data Set Ready is active
   putc(LF); putc(CR);
   Delay_Ms(1000);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
while(true)
     {
      if(rcvd_uart)
      {  rcvd_uart = 0;
         PORTD = b ;
         while (BUSY);
         STROBE=0;
         delay_us(1);
         STROBE=1;
         DSR=0;  // Data Set Ready is active
      }
     }
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Nov 30, 2008 10:28 am     Reply with quote

With PC RS232 hardware handshake, CTS rather than DSR is the signal to be used to signal peripheral busy/ready state.
oyhan



Joined: 03 Jun 2005
Posts: 21
Location: TURKEY

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sun Nov 30, 2008 3:47 pm     Reply with quote

Hi again..
I checked CTS RTS signal but they are same. No difference.
My code lose some characters. What is my code problem?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 30, 2008 3:56 pm     Reply with quote

Post the manufacturer and part number of your printer.
oyhan



Joined: 03 Jun 2005
Posts: 21
Location: TURKEY

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sun Nov 30, 2008 4:14 pm     Reply with quote

For example If I Send some characters with a file from pc lpt1 port I do not see any problem.
"c:\>copy lpt1 test.txt" this printer is write easily and true.
My printer information:
CARD STAR
Thermodrucker
Artikel-Nr.:0810
celectronic
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 30, 2008 4:23 pm     Reply with quote

Post a link to the webpage that has a data sheet or manual for the printer.
oyhan



Joined: 03 Jun 2005
Posts: 21
Location: TURKEY

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Dec 01, 2008 3:24 pm     Reply with quote

How can I do that? For my problem..
Ttelmah
Guest







PostPosted: Mon Dec 01, 2008 3:40 pm     Reply with quote

I'd suggest you try 'early stopping'.
CTS usually affects the daa being loaded to the transmission, rather than the UART directly. If you are running with a normal modern UART, a few characters actually 'in transmission', can still be sent after you say it is not 'clear to send'.
So, use an interrupt driven serial buffer, like EX_SISR. Have this using a buffer of (say) 64 characters, and signal it is not clear to send, when this gets to perhaps 3/4 full (48 characters). Only re-enable the comms, when the buffer empties.
This is the 'normal' strategy used in such handling, and should avoid loss of characters.
In your case, at the least, the character in the outgoing shift register, and possibly a couple in the incoming shift register and latch, could all arrive after the line activates. Possibly more.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group