Hi all,
Am able to get a digital input at D_IN1. I am trying to check this using an LED at PORTJ. So what i do here is whenever the corresponding LED of D_IN1 goes high i should make an LED glow. My LED that corresponds to D_IN1 is glowing but the condition that is use to make PORTJ LED is not working. Can anyone correct my error here?
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#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
#pragma interrupt interrupthandler
#define LED PORTCbits.RC2
void interrupthandler( ) ;
void function ( ) ;
void data( ) ;
unsigned char a[ 10 ] ;
unsigned char ucCharBuff[ 10 ] ;
int i = 0 ;
int j = 0 ;
void main( void ) {
OSCTUNE = 0x40 ;
TRISG = 0 ;
PORTG = 0X40 ;
TRISC = 1 ;
TRISJ = 0 ;
Open1USART(
USART_TX_INT_ON & //Enabling USART
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
67 ) ;
RCONbits.IPEN = 0 ;
INTCONbits.GIE = 1 ; //Enabling interrupts
INTCONbits.PEIE = 1 ;
PIE1bits.RC1IE = 1 ;
ADCON1 = 0X0F ; // dISABLING ANALOG INPUTS
// RCSTA1bits.CREN = 0;
Delay100TCYx( 100000 ) ;
ucCharBuff[ 0 ] = 0x34 ; // rfid tag code is stored in ucCharBuff.
ucCharBuff[ 1 ] = 0x32 ;
ucCharBuff[ 2 ] = 0x30 ;
ucCharBuff[ 3 ] = 0x30 ;
ucCharBuff[ 4 ] = 0x41 ;
ucCharBuff[ 5 ] = 0x34 ;
ucCharBuff[ 6 ] = 0x33 ;
ucCharBuff[ 7 ] = 0x35 ;
ucCharBuff[ 8 ] = 0x42 ;
ucCharBuff[ 9 ] = 0x31 ;
while ( 1 ) {
}
Close1USART( ) ;
}
#pragma code interruptvectorhigh=0x08
void interruptvector( void ) //interrupt vector
{
_asm
goto interrupthandler
_endasm
}
#pragma code
//interrupt routine
#pragma interrupt interrupthandler
void interrupthandler( ) {
if ( PIR1bits.RC1IF == 1 ) {
PIR1bits.RC1IF = 0 ;
for ( i = 0 ; i < 10 ; i++ ) {
a[ i] = RCREG1;
}
for ( j = 0 ; j < 10 ; j++ ) {
if ( a[ j] == ucCharBuff[ j] )
function ( ) ;
}
}
}
void function ( ) {
WDTCONbits.SWDTEN = 1 ;
PORTG = 0X00 ;
for ( j = 0 ; j < 20 ; j++ ) {
Delay10KTCYx( 1000 ) ;
}
PORTG = 0X40 ;
for ( j = 0 ; j < 20 ; j++ ) {
Delay10KTCYx( 1000 ) ;
data( ) ;
}
PIE1bits.RC1IE = 0 ;
WDTCONbits.SWDTEN = 0 ;
}
void data( ) {
while ( LED == 1 ) {
PORTJ = 0X02 ;
}
}
Last edited by a moderator: Jan 8, 2013