I don't receive Serin2 data

Başlatan Cesar35, 21 Eylül 2023, 13:22:39

Cesar35

Hello ETE
All very well
Clear my doubts with this pic16f1827
I can't receive the data
There is no reference to pic16f1827, I don't know what's wrong here, follow the code
Thanks
RX:
#header
  errorlevel -303  ; suppress Program word too large
#ENDHEADER

#CONFIG
  __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _CLKOUTEN_OFF & _IESO_ON & _FCMEN_OFF
  __config _CONFIG2, _WRT_ALL & _PLLEN_OFF & _STVREN_OFF & _LVP_OFF & _BORV_19 & _LVP_OFF 
#ENDCONFIG

'************************************************************************
DEFINE OSC 4

ANSELA=0:TRISA=%11110011:LATA=0:PORTA=0:WPUA=0 'MCLR PÝNÝ DAÝMA GÝRÝÞ OLARAK AYARLANMALI !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
ANSELB=0:TRISB=%00000000:LATB=0:PORTB=0:WPUB=%00000000  

OSCCON = %01101000   ' 4MHz internal %0xxxx000 ,xxxx=1111 16Mhz, 1110=8Mhz, 1101=4Mhz, 1100=2 Mhz.
ANSELA = 0           ' all digital. A/D disabled
ANSELB = 0

MDCON = 0
CM1CON0=0
CM2CON0=0
DACCON0=0
CPSCON0=0
FVRCON=0
CCPTMRS=0
APFCON0=0

'----[VARIAVEIS]----------------------------------------------------------------
RX   VAR BYTE
I    VAR BYTE
TEMP VAR BYTE
'----[DEFINE PORTAS BOTOES]-----------------------------------------------------
SYMBOL  RX_IN=PORTA.0
'----[DEFINE PORTAS SAIDAS ]----------------------------------------------------
SYMBOL  LED1=PORTA.2  'BUZZER DE ENDICAÇÃO SONORO
SYMBOL  LED2=PORTA.3  'BOMBA DE AGUA1

INICIO:
       high led1
       PAUSE 200
       low led1
       pause 200
       high led1
       TEMP = 150
PROG:
      Serin2 RX_IN,84,300,SAIR,[WAIT("CMD"),RX]
      If RX = "A" Then PARA_CIMA
      If RX = "B" Then PARA_BAIX
      If RX = "C" Then ESQ
      If RX = "D" Then DIR
      IF RX = "E" THEN EFE
      GOTO PROG   

PARA_CIMA:
    For i = 0 To 4
    LookUp i,[1,2,4,8],PORTB  
    pause TEMP  
    Next i
    Goto PROG

PARA_BAIX:       
    For i = 0 To 4
    LookUp i,[8,4,2,1],PORTB 
    pause TEMP  
    Next i
    Goto PROG
ESQ:     
    For i = 0 To 4
    LookUp i,[16,32,64,128],PORTB  
    pause TEMP  
    Next i
    Goto PROG
DIR:       
    For i = 0 To 4
    LookUp i,[128,64,32,16],PORTB  
    pause TEMP  
    Next i
    Goto PROG
    END
    
EFE:
    HIGH LED2
    PAUSE 200
    LOW LED2
    GOTO PROG
SAIR:
    PORTB=%00000000
    GOTO PROG 


TX
#CONFIG
    __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _CP_OFF & _BOREN_OFF  & _WDTE_OFF & _PWRTE_OFF  & _CPD_OFF 
#ENDCONFIG
'-----[ CONFIGURAÇÃO CRISTAL]---------------------------------------------------
DEFINE OSC 4

Define OSCCAL_1K 1       ' Calibrate internal oscillator
' Define ADCIN parameters
Define ADC_BITS 10       ' Set number of bits in result
Define ADC_CLOCK 3       ' Set clock source (3=rc)
Define ADC_SAMPLEUS 50  ' Set sampling time in uS

'-----[ CONFIGURAÇÃO DE PORTAS]-------------------------------------------------

TRISIO.0=1 ' GPIO.0 As Saida
TRISIO.1=1 ' GPIO.1 As Entrada
TRISIO.2=0 ' GPIO.2 As Saida
TRISIO.3=1 ' GPIO.3 As Saida
TRISIO.4=1 ' GPIO.4 As Saida
TRISIO.5=1 ' GPIO.5 As Saida     

'-----[ DEFINIÇÃO DE PORTAS]----------------------------------------------------
SYMBOL TX=GPIO.2
SYMBOL SW=GPIO.5

'-----[ DEFINIÇÃO VARIAVES]----------------------------------------------------
POT1 var WORD
POT2 VAR WORD

'----[INICIO DO PROGRAMA]-------------------------------------------------------
ADCON0 = %10000001' Right justified results & enable A/D
ANSEL = %00110011 ' Clock source=FRC
CMCON = 7         ' Analog comparators off
Pause 500         ' Wait .5 second for LCD to init

'-----[ PROGRAMA ]-------------------------------------------------------------
 
main:
    IF SW = 0 THEN
    serout2 TX,84,["CMDE"]
    ENDIF
    
    adcin 0,POT1:POT1=POT1/4
    ADCIN 1,POT2:POT2=POT2/4
    
    IF POT1 > 200 THEN
    serout2 TX,84,["CMDA"]
    ENDIF
        
    IF POT1 < 20 THEN
    serout2 TX,84,["CMDB"]
    ENDIF
        
    IF POT2 > 200 THEN
    serout2 TX,84,["CMDC"]
    ENDIF
        
    IF POT2 < 20 THEN
    serout2 TX,84,["CMDD"]
    ENDIF
    
    goto main

ete

If you do not delete the following lines you cannot get any data from the TX. There are the lines which destroy the communications by PAUSE command. Because the Tx are sending the information while RX processing the PAUSE command. Pause a special command until it is finish not one information can be received. Delete them and see what is going on.
I did not see any other problem.

	       high led1
	       PAUSE 200
	       low led1
	       pause 200
	       high led1
	       TEMP = 150

Ete

Cesar35

Thanks for your response
And it doesn't work
I wonder if the port input settings are 0, this pic16f1827 has analog and digital pins
Thanks

ete

You right. The problem is on the RX side and there is a command as follows;
ANSELA = %11110011 ' Set PORTA pins to digital I/O
this command line should be deleted. Because it is arranging the input pins to Analog pins and PORTA.0 is not an ANALOG pin it is Digital INPUT pin. If you delete that line the program is starting to work. I suggest you to make some changes as follows;
Make a correction on TX as follows;
'Define ADCIN parameters
Define ADC_BITS 10       ' Set number of bits in result
Define ADC_CLOCK 3       ' Set clock source (3=rc)
Define ADC_SAMPLEUS 20  ' Set sampling time in uS

main:
    IF SW = 0 THEN
    serout2 TX,84,[REP$AA\5,REP$00\5,REP$FF\5] 
    serout2 TX,84,["CMDE"]
'    pause 100
    ENDIF
Delete the Timout label and time on SEROUT2 command they do not work.

On RX side you need to delete one line only;

'ANSELA = %11110011 ' Set PORTA pins to digital I/O

Ete

Powered by EzPortal