Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Problem with PIC18F97J60 board

Status
Not open for further replies.

Mhadhu

Junior Member level 2
Junior Member level 2
Joined
Jan 3, 2013
Messages
21
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,461
Whenever i dump a code in PIC board the code works good for certain instants but the code after few minutes doesn't work properly. Is there any problem with my code or with the development board?

my code is to turn on an led whenever a digital input is obtained.

CODE:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <p18f97j60.h>
#include<delays.h>
#include<usart.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF
#pragma config WDTPS=256
void data();
int a;
void main(void) {
    OSCTUNE = 0x40;
    TRISC = 1;
    TRISJ = 0;
    PORTJ = 0X00;
    TRISG = 0;
    PORTG = 0X00;
    ADCON1 = 0X0F; // dISABLING ANALOG INPUTS
    CMCON = 0X07; //disabling comparator
    while (1) {
        PORTG = 0X40;
        data();
        
    }
}
 
void data() {
    a=PORTCbits.RC2;
    if (a==1) {
       LATJ =0x02;;
    }
}

 
Last edited by a moderator:

If your input is on RC2, the proper value for TRISC should be 0x04, not 0x01.

Code:
extern volatile near unsigned char       PORTC;
extern volatile near union {
  struct {
    unsigned RC0:1;
    unsigned RC1:1;
    [COLOR="#FF0000"]unsigned RC2:1;[/COLOR]
    unsigned RC3:1;
    unsigned RC4:1;
    unsigned RC5:1;
    unsigned RC6:1;
    unsigned RC7:1;
  };
  struct {
    unsigned T1OSO:1;
    unsigned T1OSI:1;
    unsigned CCP1:1;
    unsigned SCK:1;
    unsigned SDI:1;
    unsigned SDO:1;
    unsigned TX:1;
    unsigned RX:1;
  };
  struct {
    unsigned T13CKI:1;
    unsigned CCP2:1;
    unsigned :1;
    unsigned SCL:1;
    unsigned SDA:1;
    unsigned :1;
    unsigned CK:1;
    unsigned DT:1;
  };
  struct {
    unsigned :1;
    unsigned ECCP2:1;
    unsigned ECCP1:1;
    unsigned SCK1:1;
    unsigned SDI1:1;
    unsigned SDO1:1;
    unsigned TX1:1;
    unsigned RX1:1;
  };
  struct {
    unsigned :3;
    unsigned SCL1:1;
    unsigned SDA1:1;
    unsigned :1;
    unsigned CK1:1;
    unsigned DT1:1;
  };
} PORTCbits;

Code:
#include <p18f97j60.h>
#include<delays.h>
#include<usart.h>
#pragma config XINST=OFF
#pragma config WDT=OFF, FOSC2=ON, FOSC=HSPLL, ETHLED=OFF
#pragma config WDTPS=256
void data();
int a;
void main(void) {
    OSCTUNE = 0x40;
[COLOR="#FF0000"]    TRISC = 1;  // Configures Input on RC0, not RC2[/COLOR]
    TRISJ = 0;
    PORTJ = 0X00;
    TRISG = 0;
    PORTG = 0X00;
    ADCON1 = 0X0F; // dISABLING ANALOG INPUTS
    CMCON = 0X07; //disabling comparator
    while (1) {
        PORTG = 0X40;
        data();
        
    }
}
 
void data() {
    a=PORTCbits.RC2;
    if (a==1) {
       LATJ =0x02;;
    }
}

Try:

Code:
    TRISC = 0x04;

Or Simple:

Code:
    TRISC = 0xFF;

To configure all available pins of PORTC to inputs.


Also, once RJ2 is set high, it remains high/active regardless of the state of RC2.


Another possible issue, if the input is from a bouncy switch, then either hardware or software debounce methods are typically implemented.

What exact is the task of your code, in detail?


BigDog
 

task is whenever the rfid generates an output it is fed as input as input to D_IN1. which is port c 3rd pin. i have to check for that input periodically. whenever input is obtained a task has to be done. for simplicity now am glowing an led.
 

A more efficient method would be to utilize an External Interrupt in conjunction with an Interrupt Service Routine (ISR), rather then the current polling method.

Another option would be the use of an Interrupt-On-Change in conjunction with an ISR, however they can be a little more tricky to utilize correctly.

Setting TRISC to the proper value should help in the implementation of your current polling method.

BigDog
 

I changed the TRISC value as u said.. but nothing worked.. Its the same.. Can u plz explain it clearly... ??
 

The problem was with watchdog timers. It is solved now!! Thanks for ur help..
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top