|
|
View previous topic :: View next topic |
Author |
Message |
ikeme
Joined: 23 Nov 2005 Posts: 2 Location: uk
|
ER400TRS USING PIC C PROGRAMMING |
Posted: Mon Nov 28, 2005 1:12 pm |
|
|
CAN SOMEONE HELP ME TO AMEND THIS CODE
ITS MET TO BE DOING
PIC C programme that will echo back every ASCII character received on the ER400TRS connected to the PICRadio PCB
#include <16F876.h>
//#device 16F876 ICD=TRUE
#use delay(clock=4000000)
#fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, ERRORS)
void main()
{
unsigned char c;
while(TRUE) // do forever
{
// host is ready
// receive byte
if(!(input(PIN_C4)))
{
c=getc();
output_high(PIN_C3);
putc(c);
delay_ms(1000); // send characters every 1 sec
output_high(PIN_C2);
delay_ms(1000); // send characters every 1 sec
}
}
} _________________ erefaaco |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 28, 2005 1:38 pm |
|
|
Add the NOLVP fuse. Without that fuse, your program could be locking up
and you might falsely think it's due to a coding problem. Example:
#fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Nov 28, 2005 8:03 pm |
|
|
Code: | #fuses XT,NOWDT, NOPROTECT, NOPUT, NOBROWNOUT, NOLVP
#define XTAL_FREQ 4000000
#use delay(clock=XTAL_FREQ,RESTART_WDT)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,errors, restart_wdt)
// Serial Ring Buffer and control registers
#define CCRSize 64 // Command Construction Buffer size
// Console Rx Ring Buffer control
byte RxHeadC; // Console Ring Buffer Head pointer
byte RxTailC; // Console Ring Buffer Tail pointer
// allocate communications buffer memory
#define RxCQsize 64 // Console Rx buffer size
byte RxBaseC[RxCQsize]; #locate Rx_BaseC = 0x0190 // Console Rx Buffer location
// Tell compiler where to find serial control registers and bits for PIC16F87x
#byte RCREG = 0x1A
#byte RCSTA = 0x18
#define OERR 1
#define CREN 4
#int_RDA
void serial_isr()
{
// ; test for overrun error
if (bit_test(RCSTA, OERR))
{
bit_clear(RCSTA, CREN); // clear continous receive bit
bit_set(RCSTA, CREN); // set continous receive bit
}
RxBaseC[RxHeadC++]=getc();
RxHeadC %= RxCQsize;
}
char getc_QConsole()
///////////////////////////////////////////////////////////////////////////
//
// getc_QConsole
//
// Routine to read (remove) a byte from the Console receive buffer
//
// On Entry:
// Rx_TailC points to next byte to be read from the logger receive buffer
//
// On Exit:
// Rx_TailC points to the next position in the buffer
//
//
// Calls:
//
///////////////////////////////////////////////////////////////////////////
{
Char RxChar;
RxChar = RxBaseC[RxTailC++];
RxTailC %= RxCQSize;
return(RxChar);
}
void main ()
{
int i;
disable_interrupts(global);
// setup_wdt(WDT_ON);
restart_wdt();
// initialise Console receive buffer pointers
RxHeadC = 0;
RxTailC = 0;
// initialise the console receive USART status
i = RCREG;
i = RCREG;
if (Bit_test(RCSTA,OERR))
{
// here on overrun error - need to reset the USART
bit_clear(RCSTA,CREN); // clear continous receive bit
bit_set(RCSTA,CREN); // set continous receive bit
}
// disable UART Rx interrupt
clear_interrupt(INT_RDA); // clear interrupt flag
enable_interrupts(INT_RDA); // enable the interrupt
enable_interrupts(global);
for (;;)
{
// host is ready
// receive byte
if(!(input(PIN_C4)))
{
if (RxHeadC != RxTailC)
{
c=getc_QConsole();
output_high(PIN_C3);
putc(c);
delay_ms(1000); // send characters every 1 sec
output_high(PIN_C2);
delay_ms(1000); // send characters every 1 sec
}
}
}
}
|
_________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|