Hi,
I'd like to send an array of 70 bytes to a PC using the serial port.
Hardware connection:
I plan to connect PIC pin RA5 to DB9 pin 2 (RX) of the pc via an inline 1K resistor.
(By the way, my pic pin RA5 has a 100K weak pull down because of the way I use the pin when not using it to transfer data).
I put the following line at the top of the code:
Code:
Include "modedefs.bas"
'Predef config at flashing time
@ device pic16F690, intrc_osc_noclkout, BOD_OFF, PWRT_OFF, wdt_off, mclr_off, protect_off
I also use:
Code:
DEFINE OSC 8 'set OSC value to 8MHz for instructions PAUSE, PAUSEus and SOUND (instead of default 4MHz)
DEFINE CHAR_PACING 1000
and:
Code:
CLEAR
INTCON = 0 'disable interrupts and clear int flags
OSCCON = %01110001 'set osc to internal, HS 8MHz
'SETTINGS for this register:
'bit 7: not used: 0
'bits 6-4: IRCF bits: 8MHz internal oscillator: 111 (after a reset: auto sets to 110 = 4 MHz)
'bit 3: OSTS bit: device is running from one of the two internal sys clocks (HFOSC or LFOSC): 0
'bit 2: HTS bit: high freq 8MHz-125KHz status bit: shows if HFINTOSC is stable or not: 0
'bit 1: LTS bit: low freq 31Khz status bit: shows if LFINTOSC is stable or not: 0
'bit 0: SCS bit: sys clock selection bit: internal oscillator is used for system clock: 1
'''''''CMCON0 = %00000111 'comparators OFF, val = 7
CM1CON0.7 = 0 'disable comparator1
CM2CON0.7 = 0 'disable comparator2
ANSEL = %00000000 'choose digital i/o, val = 0
ANSELH = %00000000 'PIC16F690 specific
ADCON0.0 = 0 'turn adcon off (is already off by default)
OPTION_REG = %01111111 'enable porta weak pullups (no weak pull-up available for porta.3), p12
'bit7: pull ups are enabled by individual port latch values
'-------------------------------------------------------------------------------
TRISA = %111111 'all porta pins are set to input (high impedance) (portA.3 is always input pin, datasheet p5), beware of floating pins
'-------------------------------------------------------------------------------
'RA5 is used in default as an input, LOW (100K ext WPD) because it waits for a +5V pulse to bring it HIGH
TRISB = %0000
TRISC = %00000000 'all portc pins are set to output mode, PWM starts if CCP1CON is enabled
'-------------------------------------------------------------------------------
WPUA = %011111 'enable internal weak pull ups resistors individually on portA pins to bring them HIGH internaly, except for porta.3 for which the pullup is auto set if pin is enabled as MCLRE (Ra3 can be set as mclr or as i/o port with config words)
'-------------------------------------------------------------------------------
WPUB = %0000
'enable for RA0-4,(RA3 has an external 10k WPU, no internal WPU is available except automaticaly if used as MCLR)
'RA5 is LOW as default, it has an external 100k WPD (input as default).
'MEMO: when pic powers up all ports are set to inputs
'-------------------------------------------------------------------------------
PORTA = %011111 'set pins logic
'-------------------------------------------------------------------------------
PORTB = %0000
PORTC = %00000000 'set pins logic
'All are set to low by default, pins with pullups are brought automaticaly HIGH anyway
and just before the ON INTERRUPT I have:
Code:
'set as output low
TRISA.5 = 0
PORTA.5 = 0
FOR i = 128 to 197
read i,hits_count 'get the number of times player was hit by this opponent
SEROUT PORTC.5,T9600,[hits_count]
NEXT i
'restore as input low
TRISA.5 = 1
PORTA.5 = 0
What will be output? RS232 level so I can connect it directrly to the PC or should I use MAX232 chip???
Thanks!
Bookmarks