Workshop 8: Read and Writing to PC

 

Purpose: Using the embedded controller read and write data to and from a PC.

Objective: This workshop is designed to familiarize the student with elements of the embedded microcontroller.

Real world application: PC interface with embedded controller.

Requirements:

Hardware: Pin9 RS-232 connector , Max 233 (TTL to RS-232 converter chip), Scott Edwards Serial LCD

Procedure: Design and implement a program that will communicate from a Picstic to the PC and from the PC to the Picstic. Write a simple Qbasic program that will run on the PC. The program shall wait for a input message from the Picstic, when received it will transmit a reply message. Write Pbasic program that will transmit a message to the PC, then wait for the a reply message. Each time a message is received display the message, for the PC display the message on screen, for the Picstic display the message on an LCD. The following Qbasic code segments should help get you started:

OPEN "com1:2400,n,8,1,cd0,cs0,ds0,op0,RB1000" FOR RANDOM AS #1
CLS 'clears the screen
PRINT "<expression>" 'prints to screen
PRINT "" 'carriage return
data$ = INPUT$(1, #1) 'takes input for COM1
PRINT data$; 'print input
PRINT #1, CHR$(89); CHR$(69); CHR$(83); CHR$(32); 'outputs on COM1 "YES "

Circuit Drawing for Workshop #8

PicBasic Code for Workshop #8

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

'This program will communicate between the Picstic and a PC. To
'accomplish this task a Qbasic program must be running on the PC.
'Herb Wagner

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

BEGIN:
       serout 7,N2400,(254,1)                 'clear LCD
       serout 7,N2400,("test LCD")         'test message
SEND: serout 0,T2400,("PIC: I am here!",0)           'send this
                                                                     'message out to PC

GET: serin 1,T2400,b2,b3,b4,b5,b6,b7,b8,b9,b10      'receive message
                                                                           'from PC store it
                                                                           'b2 thru b10
         serout 7,N2400,(254,1)                                     'clear LCD
         serout 7,N2400,(b2,b3,b4,b5,b6,b7,b8,b9,b10)     'output message
                                                                                'on LCD
         serout 0,T2400,("PIC: We are talking!,0")            'send message to PC
end

Qbasic Code for Workshop #8

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

 

'This PC (Qbasic) program will take input messages from the Picstic
'and send output messages to the Picstic.
'Herb Wagner

'$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

     OPEN "com1:2400,n,8,1,cd0,cs0,ds0,op0,RB1000" FOR RANDOM AS #1
BEGIN:
        CLS                                                              'clear the screen
        PRINT "PC: Picstic are you out there?"        'print to screen
        PRINT ""                                                        'carrage return

'///////////////////////////////////////////////////////////////////////

receive:
      data$ = INPUT$(1, #1)            'receive input message
      PRINT data$;                         'print input message to
                                              'screen
      IF ASC(data$) = 0 THEN GOTO gotit             'jump if message received
      GOTO receive

'///////////////////////////////////////////////////////////////////////

gotit:
     PRINT ""
     PRINT ""
     PRINT "PC: Heard you loud and clear"              'print to screen
     PRINT "PC: Can you hear me?"                       'print to screen

'///////////////////////////////////////////////////////////////////////

'send out the following characters
        PRINT #1, CHR$(89); CHR$(69); CHR$(83); CHR$(32);
        PRINT #1, CHR$(73); CHR$(32);
        PRINT #1, CHR$(67); CHR$(65); CHR$(78);
        PRINT ""                                                  'carriage return
        data$ = INPUT$(20, #1)                            'receive input message
        PRINT data$;                                           'print input message to
                                                                  'screen
END