News:

;) This forum is the property of Proton software developers

Main Menu

HSER and Digital pin

Started by midali, Jun 16, 2024, 05:47 PM

Previous topic - Next topic

midali

Hi friends,

In 16F1939 ,PORTC.6 is TX if I use a hardware serial . May I use it like a digital pin ?
The motherboard is ready and can't change with another port.


;-------------------------------------------------------------------------------
Device = 16F1939

Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, CP_ON, CPD_OFF, BOREN_OFF, CLKOUTEN_OFF, IESO_OFF, FCMEN_OFF
Config2 WRT_OFF, VCAPEN_OFF, PLLEN_OFF, STVREN_OFF, LVP_OFF

Declare  Xtal = 32
OSCCON  = %11110100 'set to 8 x 4PLL MHz

Declare Hserial_Baud   = 115200
Declare Hserial_Clear  = On
Declare CCP1_Pin   = PORTC.2
Declare CCP2_Pin   = PORTC.1

Dim ch1 As Word
   
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
TRISA =  %00001111 : TRISB =  %00000000 : TRISC =  %10000001 : TRISD =  %00000000 : TRISE =  %00000000       
ANSELA = %00000011 : ANSELB = %00000000 : ANSELD = %00000000 : ANSELE = %00000000
PORTA  = %00000000 : PORTB = %00000000  : PORTC = %00000000  : PORTD = %00000000  : PORTE = %00000000
;-------------------------------------------------------------------------------


;===============================================================================   
main:
    HSerIn [ch1]
        Toggle PORTC.6
        DelayMS 500
GoTo main

top204

You can try and disable the TX part of the USART, but on the earlier 8-bit PIC devices, it does not always work as expected.

Try:

TXSTAbits_TXEN = 0

This will clear the TXEN bit of the TXSTA register.

midali

Its working.

Thank you Mr Les!