PDA

View Full Version : How to do the "SerIN" and "SerOut " for the usb ?



vicce67
- 13th March 2015, 01:14
Dear Friends,

I am making the communication as in the code below saw rs232.
I want to do using the usb and the pic18f4550 I don't get.
How to do the "SerIN" and "SerOut " for the usb ?
Some of the friends could help with the code

In advance thankful,
Vicente.
Excuse my English I am Brazilian.


;Definicoes 18F4550
@ __CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC1_PLL2_1L & _USBDIV_2_1L
@ __CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEN_OFF_1H & _IESO_OFF_1H

@ __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_ON_2L & _BORV_3_2L & _VREGEN_ON_2L
@ __CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H

@ __CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_OFF_3H & _CCP2MX_ON_3H & _LPT1OSC_ON_3H

@ __CONFIG _CONFIG4L, _LVP_OFF_4L & _ICPRT_OFF_4L & _XINST_OFF_4L & _STVREN_OFF_4L & _DEBUG_OFF_4L

@ __Config _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L
@ __Config _CONFIG5H, _CPD_OFF_5H & _CPB_OFF_5H

@ __Config _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
@ __Config _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H

@ __Config _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
@ __Config _CONFIG7H, _EBTRB_OFF_7H

INCLUDE "modedefs.bas"
Include "cdc_desc.bas"
Define OSC 48

;********* PORT A
ADCON1 = %00001111 ;Turn off all AD's
TRISA = %11010100 'PortA
PORTA = %00000000
;********* PORT B
INTCON2.7=0 ; Enable PORTB pullups
TRISB = %11011111 'PortB
PORTB = %00000000
;********* PORT C
TRISC = %10111111 'PortC
PORTC = %01111111
;********* PORT D
TRISD = %11111111 'PortD
PORTD = %00000000
;********* PORT E
TRISE = %11111111 'PortE
PORTE = %00000000
;************************************************* ****************************
; DEFINICOES DAS CONSTANTES E VARIAVEIS *
;************************************************* ****************************
define i2c_sclout 1
define i2c_hold 1
define i2c_slow 1
define ser2_bits 8
define shift_pauseus 100
;***************************** Alias Dos Pinos *******************************
SDA_Chave VAR PORTB.4
SCL_Chave VAR PORTB.5
;***************************** Comunicacao serial 232
Modo_232 con 16390
Ctrl_Chave con %10100000;Endereco Fisico
;*************** DEFINICOES DAS VARIAVEIS
Hc var byte[150]
Work_Word VAR word
K VAR BYTE
X VAR BYTE
;************************************************* *****************************
; TECLA *
;************************************************* *****************************
Tecla:
SerIn2 portc.7,Modo_232,200,Tecla,[wait($AA),x,k] ;

if x="P" and k="O" then
high porta.3;led
goto Tecla
endif

if x="E" then
for work_word=20 to 1307 step 13
I2cread sda_chave,scl_chave,Ctrl_Chave,work_word,[hc[100],hc[101],hc[102],hc[103],hc[104],hc[105],hc[106],_
hc[107],hc[108],hc[109],hc[110],hc[111],hc[112]]
SerOut2 portc.6,Modo_232,["!",dec5 work_word,",",dec2 hc[100],dec2 hc[101],dec2 hc[102],dec2 hc[103],dec2 hc[104],_
dec2 hc[105],dec1 hc[106],dec1 hc[107],dec1 hc[108],dec1 hc[109],dec1 hc[110],dec1 hc[111],dec3 hc[112],"&"];
next
SerOut2 portc.6,Modo_232,["K"]
goto tecla
endif

goto Tecla

gadelhas
- 13th March 2015, 02:01
http://www.picbasic.co.uk/forum/content.php?r=377-usb