hi,
I need your help.
I use the EASYPIC7 with PIC18f26k83 and Mikrobasic.
I have a problem when use Uart, when send any chars on RC7 pin the micro freezes.
I have test without serial connection and if I push button on rc7 on easypic7 the micro is freezes, timer0 not work, I think more peripherials...
I don't understand why....
Any clarification is goog
I send my test code below:
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
'interrupt Timer0 @ 1ms
sub procedure Initinterrupt()
GIE_bit = 1 'Enables all unmasked interrupts
'timer0
T0CON0 = %10010000 'enable TMR0 Enable bit 8 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
'uart
PIE3.U1IE = 1 'attivo Interrupt su seriale uart1
PIE3.U1RXIE = 1
end sub
sub procedure Interrupt()
'TIMER0
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
Initinterrupt()
'configuro ingressi e uscite
trisa = %00001111
trisb = %00111111
trisc = %10000000
'configuro ingreesi analogici e digitali
ANSELA = %00001111
ANSELB = %00000000
ANSELC = %00000000
ODCONA = %00000000
ODCONB = %00000000
ODCONC = %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)
Unlock_IOLOCK()
PPS_Mapping(_RC7, _INPUT, _RX1)
PPS_Mapping(_RC6, _OUTPUT, _TX1PPS)
Lock_IOLOCK()
delay_ms(100)
UART1_Remappable_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_Remappable_Write_Text(INGRESSOANA)
UART1_Remappable_Write(13)
T2 = 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.
uart problem PIC18F26K83
- IvanJeremic
- mikroElektronika team
- Posts: 316
- Joined: 05 Sep 2022 14:32
Re: uart problem PIC18F26K83
Hi,
Try something like our example for TImer 0.
Make sure the Clock settings are configured correctly.
Regards,
Ivan.
Try something like our example for TImer 0.
Code: Select all
program Timer0_Interrupt
dim counter as word
sub procedure Timer0_Interrupt() iv 0x0008 ics ICS_AUTO
if (TMR0IF_bit = 1) then
Inc(counter) ' Increment value of counter on every interrupt
TMR0IF_bit = 0 ' Clear T0IF
TMR0L = 0 ' Set TMR0 for aproximetly 1 sec
end if
end sub
main:
ANSELC = 0 ' Configure AN pins as digital I/O
TRISC = 0 ' PORTC is output
LATC = 0xFF ' Initialize PORTC
TMR0L = 0 ' Timer0 initial value
T0CON1 = 0x48 ' Set TMR0 to 8bit mode and prescaler to 256
GIE_bit = 1 ' Enable global interrupt
TMR0IE_bit = 1 ' Enable Timer0 interrupt
T0EN_bit = 1 ' Start Timer0
counter = 0 ' Initialize counter
while TRUE
if (counter = 122) then
LATC = not PORTC ' Toggle PORTC LEDs
counter = 0 ' Reset counter
end if
wend
end.
Regards,
Ivan.