News:

Let's find out together what makes a PIC Tick!

Main Menu

PIC12F1840

Started by Teo, Oct 13, 2025, 05:45 PM

Previous topic - Next topic

Teo

Hi everyone.
I have a very strange problem with the PIC12F1840.
The code works in Proteus but does not work in reality.
I assume it is due to a misconfigured setting.
Has anyone else had this problem?
Thank you in advance,
Teo

RGV250

Hi,
I would say it is definitely config settings. I have had it before on different devices.

Bob

Fanie

Try disabling the comparator.

Difficult to help if you do not at least post a part of the code.

Stephen Moss

Quote from: Fanie on Oct 13, 2025, 10:42 PMDifficult to help if you do not at least post a part of the code.
I agree and it would also help if we know how it is not working in reality, i.e. Timer/Delay appearing to occur too quickly/slowly, no activity at all (usually wrong XTAL setting), serial comms not working as it is very diffcult to help when you don't know what the problem is beyond the well known issues of Proteus simulation not being 100% reliable/accurate.

 

Fanie

It could also be a hardware oversight.

top204

Never fully trust a simulator for the operating frequency of the device, because microchip have made the methods so convoluted and complex, and subtly different for each device, a simulator struggles to keep up with them.

Below is a code template I have used in the past, that operates a PIC12F1840 device at 32MHz using its internal oscillator.
The demo will transmit texts to a serial terminal, and if the serial terminal receives the texts as they are transmitted, then the device is operating at the correct frequency. In this case, the texts are "Hello World"

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A PIC12F1840 code listing template.
' Written by Les Johnson for the Positron8 BASIC compiler.
'
    Device = 12F1840                                                ' Tell the compiler what device to compile for
    Declare Xtal = 32                                               ' Tell the compiler what frequency the device will be operating at (in MHz)
    Declare Auto_Heap_Arrays = On                                   ' Tell the compiler to create arrays above standard variables, so assembler code is more efficient
    Declare Auto_Heap_Strings = On                                  ' Tell the compiler to create Strings above standard variables, so assembler code is more efficient
    Declare Auto_Variable_Bank_Cross = On                           ' Tell the compiler to create any multi-byte variables in the same RAM bank. For more efficiency
'
' Setup USART1
'
    Declare Hserial_Baud = 9600                                     ' Set the Baud rate for USART1
    Declare HRSOut1_Pin  = PORTA.0
    Declare HRSIn1_Pin   = PORTA.1
'
' Create any global variables here
'

'------------------------------------------------------------------------------------------
' The main program starts here
' Transmit text to a serial terminal, to make sure the device is operating at the correct frequency.
'
Main:
    Setup()                                                         ' Setup the program and any peripherals

    Do                                                              ' Create a loop
        HRsout1Ln "Hello World"                                     ' Transmit serial text
        DelayMs 500                                                 ' Wait half a second
    Loop                                                            ' Do it forever

'------------------------------------------------------------------------------------------
' Setup the program and any peripherals
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_32MHz()                                                     ' Setup the internal oscillator to operate at 32MHz
'
' Extra setups here, when required...
'
EndProc

'-------------------------------------------------------
' Setup the internal oscillator to operate at 32MHz on a PIC12F1840 device
' Input     : None
' Output    : None
' Notes     : None
'
Proc Osc_32MHz()
    OSCCON = %11110010                                              ' Enable the 4xPLL so the device operates at 32MHz with its internal oscillator
    OSCTUNE = $00
    BORCON = $00
EndProc

'------------------------------------------------------------------------------------------
' Set the config fuses for internal oscillator on a PIC12F1840 device.
'
    Config1 FOSC_INTOSC, WDTE_OFF, PWRTE_OFF, MCLRE_ON, CP_OFF, CPD_OFF, BOREN_OFF
    Config2 WRT_OFF, PLLEN_ON, LVP_OFF

Fanie

Saved !  Thank you Les.

I use iDailyDiary from www.splinterware.com.
You can use it as a diary (I use one for that) or you can use it as a notebook, and you can create as many as you want.
Under View, you select Diary Style and select either Diary or Notebook
In one of these notebooks named SWare I save information like this setup for this pic.  There is already more than 40 sticky page tabs each with pieces of code or information related to some pic or other components, displays, RTC's, GPS etc. These information's I collect from the forum or elsewhere.
If I need something on a pic it is easy to find and makes for a quick start without problems.