begin_mplab
Newbie level 1
- Joined
- Oct 28, 2014
- Messages
- 1
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 48
// LEDblink.c for Explorer 16 with a PIC24FJ256GB110
// LEDs are connected to PORT A
#include "p24Fxxxx.h"
_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON)
// main program code
int main(void)
{
int i=1;
long int j;
TRISA =0; //all A bits are output
while (1) // loop displaying shifting bit
{
for(j=0;j<100000l;j++)
PORTA=i; // output i to PORTA
i<<=1; // shift i one bit left
if(i>256)i=1; // if i> 256 reset to 1
}
}
#pragma config POSCMOD = HS // Primary Oscillator Select (HS Oscillator mode selected)
#pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRIPLL // Oscillator Select (Primary Oscillator with PLL module (HSPLL, ECPLL))
#pragma config IESO = OFF // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) disabled)
// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2 // Comm Channel Select (Emulator/debugger uses EMUC2/EMUD2)
#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
// LEDblink.c for Explorer 16 with a PIC24FJ256GB110
// LEDs are connected to PORT A
#include "p24Fxxxx.h"
#pragma config POSCMOD = HS // Primary Oscillator Select (HS Oscillator mode selected)
#pragma config OSCIOFNC = OFF // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = PRIPLL // Oscillator Select (Primary Oscillator with PLL module (HSPLL, ECPLL))
#pragma config IESO = OFF // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) disabled)
// CONFIG1
#pragma config WDTPS = PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128 // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx2 // Comm Channel Select (Emulator/debugger uses EMUC2/EMUD2)
#pragma config GWRP = OFF // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF // JTAG Port Enable (JTAG port is disabled)
//_CONFIG1( JTAGEN_OFF & GCP_OFF & GWRP_OFF & COE_OFF & FWDTEN_OFF & ICS_PGx2)
//_CONFIG2( 0xF7FF & IESO_OFF & FCKSM_CSDCMD & OSCIOFNC_OFF & POSCMOD_HS & FNOSC_PRIPLL & PLLDIV_DIV2 & IOL1WAY_ON)
//_CONFIG3( WPCFG_WPCFGDIS & WPDIS_WPDIS)
// main program code
int main(void)
{
int i=1;
long int j;
TRISA =0; //all A bits are output
while (1) // loop displaying shifting bit
{
for(j=0;j<100000l;j++)
PORTA=i; // output i to PORTA
i<<=1; // shift i one bit left
if(i>256)i=1; // if i> 256 reset to 1
}
}
I programmed the Exploer 16 with the code and it displayed the shifting bit on the LEDsplz you are using the explorer 16 in experience and the led are blinked with my configuration? or you are using the simultor of Mplabx not isis. Can you send me the link plz of just explorer 16 board to try with in my experience
thanks in advance
I am using a PIC24FJ256GB110 and the LEDs are on PORTAplz in your simulink file that your are using in the Mplabx simulator you are a pic24fj256ga010 and a led conected to port A or what is your architecture exactly?
thanks in advance
while (1) // loop displaying shifting bit
{
for(j=0;j<100000l;j++)
PORTA=i; // output i to PORTA
i<<=1; // shift i one bit left
if(i>128)i=1; // if i> 128 reset to 1
}
Clock 4MHz specified in schamtic is ognired for oscillator mode 'FRC'
// lcd.c - Explorer 16 - functions for the PC1602-J lcd display 8-bit mode
//
// see http://www.repairfaq.org/filipg/LINK/F_LCD_progr.html
#include "hardware.h"
#include "timer.h"
#include "lcd.h"
// LCD display ports etc
#define LCDdata LATE // data port
#define LCDdataEnable TRISE
#define RS LATBbits.LATB15 // RS bit in LCDstatus
#define RW LATDbits.LATD5 // read/write bit in LCDstatus
#define E LATDbits.LATD4 // enable bit in LCDstatus
#define Eenable TRISDbits.TRISD4
#define ERSenable TRISDbits.TRISD5
#define RWenable TRISBbits.TRISB15
void lcd_delay() { mSecDelay(2); } // if LCD does not work make this longer
// Write a nibble to the LCD
// may have to adjust delays to suit the processor and clock
void lcdNibble(int n)
{
int lcd=LCDdata;
lcd_delay();
LCDdata=n;
lcd_delay();
E=1; // take clock E high
lcd_delay();
E=0;
lcd_delay();
}
// Write a Control Command to the LCD
// This is written as two nibbles
void lcdCmd(int c)
{
RS=0; // Take RS pin low for command
lcdNibble(c); // Makeup Lower Nibble
}
// write a data byte to LCD
int lcdPutchar(int d)
{
// printf("%c", d);
RS=1; // Take RS pin high for data
lcdNibble(d); // Makeup Lower Nibble
return 1;
}
// Initialise the LCD in 4bit Mode
void lcdInit()
{
E=0; // take E low
RS=0; // Take RS pin low for command
RW=0; // Take RS pin low for command
// set RS, RW and E bits as output
Eenable =0;
ERSenable =0;
RWenable =0;
LCDdataEnable &= 0x0; // set bits 0-3 output for data
lcdNibble(0x3); // This put the LCD into Soft Reset
lcdNibble(0x3);
lcdNibble(0x3);
lcdNibble(0x2);
lcd_delay();
// lcdCmd(0x28); // 2 line, 4 bit mode
lcdCmd(0x38); // 2 line, 8 bit mode
lcd_delay();
lcdCmd(0x6); // increment cursor after each write
lcd_delay();
lcdCmd(0x1); // clear display
lcd_delay();
lcdCmd(0x2); // home
lcd_delay();
lcdCmd(0xF); // turn disply on
lcd_delay();
}
// move to line (1 or 2) at position >= 1
void lcdCursor(unsigned char line,unsigned char position)
{
switch (line)
{
case 1:lcdCmd (0x80 + position -1 );lcdCmd (0x80 + position -1 ); break;
case 2:lcdCmd (0xc0 + position -1 ); lcdCmd (0xc0 + position -1 ); break;
default : break;
}
lcd_delay();
}
void lcdString(unsigned char line, unsigned char position, unsigned char *string)
{
lcdCursor(line,position);
while (*string)
lcdPutchar(*string++);
}
void lcdStringAtCursor(unsigned char *string)
{
while (*string)
lcdPutchar(*string++);
}
void lcdClear(void)
{
lcdCmd(0x01);
}
void lcdHome(void)
{
lcdCmd(0x02);
}
// clear line 1 or line 2
void lcdClearLine(unsigned char line)
{
unsigned char i;
lcdCursor(line,1);
for (i=0; i<16; i++) lcdPutchar(' ');
lcdCursor(line,1);
}
void lcd_delay() { mSecDelay(2); } // if LCD does not work make this longer
#include "hardware.h"
#include "lcd.h"
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?