0
votes

I am currently working with PIC12LF1822 a Microchip series Controller. In that I need to configure EUSART in 8-bit Asynchronous mode and pulse generation of 1MHZ using PWM...

First I started with UART send and receive of data..But after setting including oscillator selection in config register, my code is not working and failed to send the character via tx pin(RA0)..

I analysed deeply,but I can't able to find a solution for this. Can anybody suggest to solve this issue.

Below I had pasted my code,

#include<htc.h>
#include <PIC12LF1822.H>
#include "BIPOLAR_SERIAL.C"

#define _XTAL_FREQ 12000000
//Configuration word 1 register for oscillator selection
__CONFIG(CP_OFF & BOREN_OFF & WDTE_OFF & IESO_OFF & FCMEN_OFF & PWRTE_ON & CPD_OFF &                 FOSC_XT);
//Configuration word 2 register for disabling Low-Voltage program
__CONFIG(LVP_OFF);



void PWM_Duty_Cyle(unsigned int duty_cyc)
{
CCPR1L = duty_cyc>>2;
CCP1CON &= 0xcf;
CCP1CON |= ((duty_cyc & 0x03)<<4);
}

void PWM_Init()
{
TRISA2 = 0;  //PWM Pin as output
CCP1CON = 0x0c;  //PWM mode: P1A, P1C active-high; P1B, P1D active-high
PR2 = 0x00;  //Timer Period Configuration
T2CON = 0x00;    //Timer2 Prescale as 1 
PWM_Duty_Cyle(0);    //Initialize PWM to 0 percent duty cycle
T2CON |= 0x04;   //Enable Timer2    
}


void main()
{
APFCON = 0;
ANSA0=0;ANSA1=0;ANSA2=0;
serial_init();
serial_tx('S');
//  PWM_Init();
//  serial_str("PIC12LF1822_TEST");
while(1)
{
 serial_tx('A');
 serial_tx(' ');
}   

}

In the above code I can't able to get character's 'A' as well as 'S'.

Note: I am using 12MHZ as Fosc and I had set the baud rate according to that..(SPBRG=77 for baud =900,brgh=1)

1

1 Answers

0
votes

What is your "SerialInit()" and "SerialTx('S')" functions doing? Post the code of these functions, I'd like to see how you're setting up your serial port

Probably you havn't set all the required bits (RCSTA, TXSTA, SPBRG). To setup these bits properly, be sure to know the appropriate BaudRate you want to have, if you need high speed be sure to setup SPBRGH correctly.

My two functions to transmit via UART when properly initialized :

void vTx232 (UC ucSend)
 {
    STATUS.RP0 = PIR1;     //Sure we're in PIR1
    while (PIR1.TXIF == 0);//While last TX not done
    TXREG = ucSend;        //Input param into TXREG
 }

void vTxString(UC *ucpString)
 {
   while (*ucpString!= 0x00)    //While string not at its end
    {
      vTx232(*ucpString);       //Send string character
      ucpString++;              //Increm string pointer
    }
 }

Datasheet : PIC12LF1822