Please help to configure PIC
AncientNord , 09-01-2024, 07:41 PM
I am new to mcu programming. and I got a little confused. is this the correct setting? I want to use the PIC16F15313 on the internal oscillator at the maximum speed of the working program in the mcu.
QDrives , 09-02-2024, 06:40 PM
Looks good. But you can simply check that by downloading it to the MCU.
AncientNord , 09-05-2024, 10:14 PM
do you have any ideas why this is not working🤔
AncientNord , 09-05-2024, 10:19 PM
in fact, my MCU is always in the "else" ... but there is a loop that should constantly check the "if" and "if else"? however, when I apply voltage to the input, nothing changes, no response
AncientNord , 09-05-2024, 10:28 PM
Robert Feranec , 09-06-2024, 01:56 PM
if this is a very first try, I would download a blinky example. If you already tried blinky and that worked, I don't know if this is a correct code, but I have seen many times, that a code was not really changing the correct registers or correct bits, so when debugging this software step-by-step, are the correct registers setting up correct values?
QDrives , 09-06-2024, 07:11 PM
What is the 'definition' of PORTAbits? Is it a struct with volatile fields?Port A also has analog, right? If it is set to analog, digital does not work.
AncientNord , 09-06-2024, 08:24 PM
in assembler i do this. What should be written in C?
AncientNord , 09-06-2024, 08:36 PM
ANSELAbits.ANSA0 = 0; //disable AN0 ANSELAbits.ANSA1 = 0; //disable AN1
AncientNord , 09-06-2024, 08:37 PM
it works) thanks for your help. it will be necessary to find a tutorial for an absolute beginner for C program PIC mcu.
AncientNord , 09-06-2024, 08:38 PM
or some program so that it translates the assembler into C
AncientNord , 09-07-2024, 02:03 AM
Simple QA. I'm using 1 method in assembler... but is it really better than the second one?
QDrives , 09-07-2024, 03:47 PM
I usually have a HardwareSetup() function. In that function I set whole registers at once.One of the functions called is to setup the pin configuration.`/* PortA: 7=Push button up, 6=Push button down, 5=LED red, 4=LED green, 3=Temperature sensor, 2=Supply voltage, 1=Current, 0=Reference voltage */ANSEL = 0x0Fu;TRISA = 0xCFu;LATA = 0x20u; /* Make LED red already on */`Do note comments too.When working with the code, use defines to test and control your output:`#define LedRedOn() do {LATA |= 0x20u;} while (0)#define IsButtonUp() ((PORTA & 0x80u) != 0u)`Usage:`if (IsButtonUp()){ LedRedOn();}`
QDrives , 09-07-2024, 03:52 PM
You do a Banksel and than a BTFSC?It has been a (very) long time ago that I wrote PIC assembly. So what is in F?
AncientNord , 09-07-2024, 04:02 PM
there is a cycle that constantly checks the input of signals. BTFSC checks the output combination. if the outputs are already configured as needed, it returns to the cycle... In the second option, regardless of whether the output signals are configured, they will still be overwritten and then return to the cycle
AncientNord , 09-07-2024, 04:04 PM
and in general I get out of this hell on assembler) better C... programming on assembler is easy but the biggest thing that kills is non-working examples and lessons through different compilers
QDrives , 09-07-2024, 04:04 PM
So does "F" refer to LATA due to the BANKSEL?Why not just "OR" 0x20u to LATA?
QDrives , 09-07-2024, 04:04 PM
In C:`LATA = LATA | 0x20u;`
QDrives , 09-07-2024, 04:06 PM
Or better still, using the define I posted earlier.`LedRedOn();`
AncientNord , 09-07-2024, 04:11 PM
because I sit in PORTA in a loop... to be honest, I look at different implementations of people's code and try to program) I understood yesterday why nothing works... there are different compilers and the syntax is different... ,mpasm, pic as, x8, in general I can't find an assembler that is relevant for the current time manual for assembler(for absolute beginers)
QDrives , 09-07-2024, 06:20 PM
Do you want to write in C or assembly?For assembly there are slightly different styles, but "syntax"... no, that is PIC core for the most part.
AncientNord , 09-07-2024, 09:53 PM
honesly? I try to write in C and the program... in C works.. but the assembler is a challenge for me 🙂 I want to understand it... as far as I understand, the analogue of the MPASM compiler is pic_as... and xc8 is for the C language
AncientNord , 09-07-2024, 09:58 PM
so I will not give up trying to write a program in assembler... but what I find on Google or YouTube is a bit confusing... different syntax... old MCU... new MCU are program differently...
AncientNord , 09-08-2024, 06:36 PM
I rewrote the program according to the PIC AS syntax ... everything works ... the question is if I already have output = 1 ... is it better to check and exit or rewrite and exit?
QDrives , 09-08-2024, 07:50 PM
What exactly do you mean with "different syntax"?"*old MCU... new MCU are program differently...*" -- I do know there is a difference between PIC12 and PIC16 (and probably PIC24 & PIC32), but the simplest would also work on the more advanced.As I stated, it has been very long ago that I wrote PIC assembly, something like 20 years ago.Have you also gone through this https://groups.csail.mit.edu/lbr/stack/pic/pic-prog-assembly.pdf document?
AncientNord , 09-08-2024, 08:09 PM
AncientNord , 09-08-2024, 08:10 PM
AncientNord , 09-08-2024, 08:10 PM
AncientNord , 09-08-2024, 08:44 PM
i too used to learn assembler in college and write programs on pic microcontrollers.. now when i tried nothing worked) MPASM latest version 5.35 mplabx... but it doesn't support my programmer😩
QDrives , 09-09-2024, 10:25 PM
You mean the difference in how to "write a binary constant"? I never use binary, always hex. But this is just me."...nothing worked..." -- Do not 'confuse' errors (with error/warning) messages to "it does not work, but I do not get a message".With error messages it is (often) easy, as long as you also state exactly what error you get.In the last picture for instance, binary constants are either not supported or noted in a different manner.As far as I know, all support hex with 0x in front of the number.
Use our interactive
Discord forum to reply or ask new questions.