arhi
Member
where to begin ... well .. let start with code .. C18, 18F4520
let us continue with schematic ... all as it suppose to be ..
MCLR is via 10K resistor to Vcc
LED is on D3 over resistor to gnd
crystal (10MHz) and 2 capacitors where they should be
decoupling 10n on both sides
100uF on power rails
the serial out (from another PIC - works perfectly, gnd's connected together) connected to RX pin on 18F4520 (no pull up's, no pull downs ... tx from 16F coming to RX of this 18F)
on RX (clearly seen by scope, one byte comes every 300ms) the line is at Vcc (5v) level and goes low when needed (bits in package).... so .. every 300ms the led should change right .... yeeeah .. if it did I'd not be posting the message ...
here's the thing ...
N - I attach the batteries (4.9V) - scope shows signals coming trough - led do not change
Y - I attach pickit2 (4.7-4.8V) - scope show identical signal - led DOES change - pic receives data ?!?!?!?!! WHY
N - I attach batteries via regulator (4.8)- no fun, led do not change
N - I attach batteries via diode (4.7V) - no fun, led do not change
N - I attach external PSU (3V - 5.5V) - no fun, led do not change
I used the same power for both PIC's, I used different power for the PIC's .. same @#%@#$_)% if 18F is powered from PK2 it works?!?!?!?
Now, please tell me wt* I'm doing wrong before I break something.
Code:
#include <p18cxxx.h>
#include <pwm.h>
#include <usart.h>
#include <delays.h>
#pragma config OSC = HSPLL
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
#pragma config CCP2MX = PORTC
#pragma config LVP = OFF
#pragma config XINST = OFF
volatile unsigned char distance;
void rx_handler (void);
#pragma code rx_interrupt = 0x08
void rx_int(void){
_asm goto rx_handler _endasm
}
#pragma code
#pragma interrupt rx_handler
void rx_handler(void){
distance = ReadUSART();
LATDbits.LATD3 ^= 1; // CHANGE LED
PIR1bits.RCIF = 0;
}
void main(){
ADCON0 = 0;
ADCON1 = 0x0F;
TRISA = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0;
TRISE = 0;
LATA = 0;
LATB = 0;
LATC = 0;
LATD = 0;
LATE = 0;
//PWM ON
T2CON = 0;
OpenPWM1(249);
OpenPWM2(249);
SetDCPWM1(1023);
SetDCPWM2(1023);
TRISCbits.TRISC7 = 1;
RCSTAbits.SPEN = 1;
// baud rate = FOSC/(64*(x+1)) // for brgh_low
// 9600 bps, 40MHz, x=64
OpenUSART(USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_LOW,
64);
LATDbits.LATD3 = 1; // TURN LED ON
RCONbits.IPEN = 1;
IPR1bits.RCIP = 1;
INTCONbits.GIEH = 1;
while(1); // do nothing
}
let us continue with schematic ... all as it suppose to be ..
MCLR is via 10K resistor to Vcc
LED is on D3 over resistor to gnd
crystal (10MHz) and 2 capacitors where they should be
decoupling 10n on both sides
100uF on power rails
the serial out (from another PIC - works perfectly, gnd's connected together) connected to RX pin on 18F4520 (no pull up's, no pull downs ... tx from 16F coming to RX of this 18F)
on RX (clearly seen by scope, one byte comes every 300ms) the line is at Vcc (5v) level and goes low when needed (bits in package).... so .. every 300ms the led should change right .... yeeeah .. if it did I'd not be posting the message ...
here's the thing ...
N - I attach the batteries (4.9V) - scope shows signals coming trough - led do not change
Y - I attach pickit2 (4.7-4.8V) - scope show identical signal - led DOES change - pic receives data ?!?!?!?!! WHY
N - I attach batteries via regulator (4.8)- no fun, led do not change
N - I attach batteries via diode (4.7V) - no fun, led do not change
N - I attach external PSU (3V - 5.5V) - no fun, led do not change
I used the same power for both PIC's, I used different power for the PIC's .. same @#%@#$_)% if 18F is powered from PK2 it works?!?!?!?
Now, please tell me wt* I'm doing wrong before I break something.
Last edited: