View previous topic :: View next topic |
Author |
Message |
dave_s
Joined: 18 Aug 2011 Posts: 8
|
PIC12F1822 pin assignment question |
Posted: Thu Aug 25, 2011 12:03 pm |
|
|
The Tx and Rx pins can be assigned to other pins (the default should be A0 and A1). I can get the serial port to work on A4 and A5 but not the default pins A0 and A1. What am I missing?
running PCM version 4.125
Code: |
#include <12F1822.h>
#device adc=10
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT
#FUSES WDT_SW //No Watch Dog Timer, enabled in Software
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#use delay(internal=32000000)
//#use rs232(baud=19200, UART1, xmit= PIN_A0, rcv=PIN_A1)
#use rs232(baud=19200, UART1, xmit= PIN_A4, rcv=PIN_A5)
#include <PIC12F1822.h>
int16 ms_counter = 0;
int1 flag = 0;
void main()
{
setup_adc_ports(sAN0);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32|RTCC_8_bit);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(1)
{
if(ms_counter >= 976)
{
ms_counter = 0;
if(flag == 0)
{
output_high(PIN_A2);
flag = 1;
}
else
{
output_low(PIN_A2);
flag = 0;
}
printf("counter print\r\n");
}
}//while
}//main
//8mhz clock divide by 32 and over flow of 256 = 1.024ms
//counter = 976 to get one second timer
#int_TIMER0
void TIMER0_isr(void)
{
ms_counter++;
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 25, 2011 1:16 pm |
|
|
I stripped your test program down to make it much more simple.
Try this transmission and Echo test. See if it works.
Code: |
#include <12F1822.h>
#FUSES NOWDT
#FUSES INTRC_IO
#FUSES NOBROWNOUT
#FUSES NOIESO
#FUSES NOFCMEN
#FUSES NOLVP
#use delay(clock=4M)
#use rs232(baud=19200, UART1)
//=======================================
void main()
{
char c;
printf("Start: ");
while(1)
{
c = getc(); // Get char from PC
putc(c); // Send it back to the PC
}
} |
|
|
|
dave_s
Joined: 18 Aug 2011 Posts: 8
|
PIC12F1822 pin assignment question |
Posted: Fri Aug 26, 2011 5:49 am |
|
|
The simple version still not working on A0 and A1.
Replaced chip with same results!
How can I read the APFCON register to see if it has been changed from default? |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Fri Aug 26, 2011 6:27 am |
|
|
I'm using the 12F1822's bigger brother, the 16F1823 as a 4 channel remote ADC widget. I found if you specify the pins, it'll use a software UART, so don't use xmit= PIN_A0, rcv=PIN_A1 etc. Instead to select which pins use UART1 or UART2. In your case try UART2.
CCS documentation didn't help with this. I found it by trial and error.
RF Developer |
|
|
dave_s
Joined: 18 Aug 2011 Posts: 8
|
|
Posted: Fri Aug 26, 2011 6:36 am |
|
|
Thank you RF_Developer that was it! |
|
|
|