pic18f26k83

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
vartisrl
Posts: 15
Joined: 22 Jun 2023 10:09

pic18f26k83

#1 Post by vartisrl » 27 Jan 2024 20:53

HI,
I have a proble with MIkrobasic when using the library command UART1_read_text
the picmicro when received from UART is blocked.

I think that the library non work with pic18f26k83.
I use Easypic7 to test

I send my code.
Please any hep is welcome.

best regards.

code:

program MyProject 'test pic18f26k83 64Mhz internal

' Declarations section
DIM SETIN as word
DIM S_SETIN as string[8]

DIM VOUT as word
DIM S_VOUT as string[8]

DIM INGRESSOANA as string [24]
DIM T1, T2, T3 as WORD

dim COMANDO as String [255]


'interrupt Timer0 @ 1ms
sub procedure InitTimer0()
GIE_bit = 1 'Enables all unmasked interrupts
T0CON0 = %10010000 'enable TMR0 Enable bit
T0CON1 = %01000100 'FOSC/4 'Prescaler Rate Select bit 1:16
TMR0H = %11111100 'vaalore partenza timer 64535
TMR0L = %00010111 '64
TMR0IF_bit = 1
TMR0IE_bit = 1
end sub

'sub procedure
sub procedure Interrupt()
if (TMR0IF_bit) then TMR0IF_bit = 0
TMR0H = %11111100 '60
TMR0L = %00010111 '176
T1 = T1 + 1
T2 = T2 + 1
T3 = T3 + 1
end if
end sub

main:
'azzero tutte le porte
porta = 0
portb = 0
portc = 0

'azzero le variabili
T1 = 0
T2 = 0
T3 = 0

'inizializzo timer0
InitTimer0()

'configuro ingressi e uscite
trisa = %00001111
trisb = %00111111
trisc = %10000000

'configuro ingreesi analogici e digitali
ANSELA = %00001111
ANSELB = %00000000
ANSELC = %00000000

'disattivo comparatori
CCP1CON = %00000000
CCP2CON = %00000000
CCP3CON = %00000000
CCP4CON = %00000000

'attivo pwm su RC2 PIN 13
PWM1_Init(1000)
PWM1_Set_Duty(126)
PWM1_Start ()
delay_ms(100)

'configurazione ADC con vref a tra 0 e 4096mV
ADC_Init_Advanced(_ADC_INTERNAL_VREFL OR _ADC_INTERNAL_FVRH4)
delay_ms(100)

'Attivo comunicazione seriale
PPS_Mapping_NoLock(_RC7, _INPUT, _RX1)
PPS_Mapping_NoLock(_RC6, _OUTPUT, _TX1PPS)
UART1_Init(19200)
delay_ms(100)


'Main program
while true

SETIN = ADC_Get_Sample(0)
WordToStr(SETIN, S_SETIN)

VOUT = ADC_Get_Sample(1)
WordToStr(VOUT, S_VOUT)

strcat2 (INGRESSOANA, S_SETIN, S_VOUT)



if T2 >= 2000 then
UART1_Write_Text(INGRESSOANA)
UART1_Write(13)
T2 = 0
END IF


If UART1_Data_Ready() = 1 then
porta.7 = 1
UART1_Read_Text(COMANDO, "OK", 15)

end if

if (COMANDO[0] = "!") and (COMANDO[0] = "F") and (COMANDO[0] = "S") then porta.6 = 1 end if
if (COMANDO[0] = "?") and (COMANDO[0] = "F") and (COMANDO[0] = "S") then porta.6 = 0 end if

'test
if T1 >= 500 then porta.4 = not porta.4 T1 = 0 end if
if T3 >= 1000 then porta.5 = not porta.5 T3 = 0 end if

'test
if VOUT >= 2000 then porta.6= 1 end if
if VOUT <= 2000 then porta.6= 0 end if

wend
end.

Richie800
Posts: 50
Joined: 09 Jul 2007 00:31

Re: pic18f26k83

#2 Post by Richie800 » 24 Feb 2024 10:52

Code: Select all

if (COMANDO[0] = "!") and (COMANDO[0] = "F") and (COMANDO[0] = "S") then porta.6 = 1 end if
if (COMANDO[0] = "?") and (COMANDO[0] = "F") and (COMANDO[0] = "S") then porta.6 = 0 end if
Your code looks like its reading the same position ("0"). Is this correct? COMANDO[0] cannot = !, F, and S.

Should it be:

Code: Select all

if (COMANDO[0] = "!") or (COMANDO[0] = "F") or (COMANDO[0] = "S") then porta.6 = 1 end if
if (COMANDO[0] = "?") or (COMANDO[0] = "F") or (COMANDO[0] = "S") then porta.6 = 0 end if
Am I reading your code correctly?
Rick

vartisrl
Posts: 15
Joined: 22 Jun 2023 10:09

Re: pic18f26k83

#3 Post by vartisrl » 11 Mar 2024 10:37

HI, I have correct the position of array [0] [1] [2]. But the uart not work. I have test the pic18f26k83 without serial connection, and the micro frezed when i push button rc7 on easypic7... Why? I think that the configuration of PPS is not correct or other problems....

vartisrl
Posts: 15
Joined: 22 Jun 2023 10:09

Re: pic18f26k83

#4 Post by vartisrl » 11 Mar 2024 10:40

Otherwise is a problem with the library UART_READ_TEXT, if not receice the delimiter the micro frezed? Is't possible?

Richie800
Posts: 50
Joined: 09 Jul 2007 00:31

Re: pic18f26k83

#5 Post by Richie800 » 16 Mar 2024 08:48

Try:

Code: Select all

    RC6PPS = 0x13				'RC6->UART1:TX1    
    U1RXPPS = 0x17				'RC7->UART1:RX1
Instead of:

Code: Select all

PPS_Mapping_NoLock(_RC7, _INPUT, _RX1)
PPS_Mapping_NoLock(_RC6, _OUTPUT, _TX1PPS)

Post Reply

Return to “mikroBasic PRO for PIC General”