EmbDev.net

Forum: µC & Digital Electronics Pulsing a pin of the PIC24F04KA201


von Soumojit Bose (Guest)


Rate this post
0 useful
not useful
Hello people. :-)
I am a beginner in the world of micro-controllers. I have the 
PIC24F04KA201 and I have been trying to pulse an LED using the internal 
clock of the microcontroller.

Here is the code that I have been using.
1
/*
2
 * File:   newmainXC16.c
3
 * Author: Soumojit Bose
4
 *
5
 * Created on February 24, 2018, 8:52 PM
6
 */
7
8
#include <p24F04KA201.h>
9
#define FOSC 32000000
10
#define FCY (FOSC/2)//This is generally crystal frequency divided by 2
11
#include <libpic30.h>
12
#include<xc.h>
13
14
15
/******************************************************************************/
16
17
/*  *** Configuration Bits Setting  *** */
18
19
_FGS(GWRP_OFF & GCP_OFF)
20
_FOSCSEL(FNOSC_PRI & IESO_OFF)
21
_FOSC(POSCMOD_HS & OSCIOFNC_ON & POSCFREQ_HS & FCKSM_CSDCMD)
22
_FWDT(WINDIS_OFF & FWDTEN_OFF)
23
_FPOR(BOREN_BOR2 & PWRTEN_OFF & BORV_18V & MCLRE_ON)
24
_FDS(DSWDTEN_OFF)
25
26
/******************************************************************************/
27
/*
28
 * 
29
 */
30
31
//void Delay(unsigned int a);
32
int main()
33
{
34
35
    
36
    TRISBbits.TRISB0 = 0;       /*  Making Pin as output                            */
37
38
    LATBbits.LATB0 = 0;         /*  Writing zero to pin 0 of port A                 */
39
40
    while(1)
41
    {
42
        LATBbits.LATB0 = ~LATBbits.LATB0;   /*  toggling state of PIN zero to one and vice versa    */
43
        __delay_ms(10); // this is actual delay time in msec 
44
    }
45
46
    return 0;
47
}

What I do not understand is how to set the OSCCCON bits so that I can 
use the internal clock of the PIC24 to do my LED pulsing. Will the 
_delay_ms() function work in the same way, if I use an external clock?

von Soumojit B. (soumojit_b643)


Attached files:

Rate this post
0 useful
not useful
Also attached here is the Proteus simulation. I have a configuration 
where I am trying to pulse the RB0 pin of the microcontroller. At first, 
I did not have CLKI and CLK0 grounded, assuming that my configuration 
bit settings had taken care of it. The simulation did not work. When I 
have the CLKI and CLKO pins grounded, the simulation works.

Am I looking at this the right way? Are my configuration bits wrong and 
the internal oscillator (32 MHz) is not being used? If so, please help 
me.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.