Hiroshi_S
Junior Member level 1
HI guys,
I am using 12f617 uC with internal oscillator with 8Mhz, I programmed three ICs with the same code all hardware are same, but among the three IC only one is working fine and other too was not giving expected output. This code is sample library which i developed for main project. All the fuse settings are same in all three iCs but why different output. Input Vcc voltage is 4V. I tried to calibrate with OSCtune register, with value '0x0000 0010', the one which is working properly started giving wrong output, but among those two ics , which were giving wrong outputs, one Ic started giving proper output. but for mas production this kind of work is not good. Previously I tried using timer instead of using delay, but I didn't get the proper 104us output using timer, so I made this current code. kindly help me to resolve this.
I am using 12f617 uC with internal oscillator with 8Mhz, I programmed three ICs with the same code all hardware are same, but among the three IC only one is working fine and other too was not giving expected output. This code is sample library which i developed for main project. All the fuse settings are same in all three iCs but why different output. Input Vcc voltage is 4V. I tried to calibrate with OSCtune register, with value '0x0000 0010', the one which is working properly started giving wrong output, but among those two ics , which were giving wrong outputs, one Ic started giving proper output. but for mas production this kind of work is not good. Previously I tried using timer instead of using delay, but I didn't get the proper 104us output using timer, so I made this current code. kindly help me to resolve this.
[CODE=c]/*Back up of uart*/
/*
* File: main.c
* Author:
*
* Created on February 23, 2021, 3:39 PM
*/
#include <xc.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <pic12f617.h>
/*
*
*/
// CONFIG
#pragma config FOSC = INTOSCIO // Oscillator Selection bits (INTOSCIO oscillator: I/O function on RA4/AN3/T1G/OSC2/CLKOUT, I/O function on RA5/T1CKI/OSC1/CLKIN)
#pragma config WDTE = OFF // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = ON // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select bit (MCLR pin is alternate function, MCLR function is internally disabled)
#pragma config CP = OFF // Code Protection bit (Program memory is not code protected)
#pragma config IOSCFS = 8MHZ // Internal Oscillator Frequency Select (8 MHz)
#pragma config BOREN = OFF //OFF // Brown-out Reset Selection bits (BOR disabled)
#pragma config WRT = OFF // Flash Program Memory Self Write Enable bits (Write protection off)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#define _XTAL_FREQ 8000000 // defining crystal value for the internal delay function
void send_serial_message(void);
void send_serial_byte(unsigned char);
void send_string(char *);
void serial_int_char(int );
#define PIN_SER_OUT PORTAbits.GP5 // pin for serial out (PORTA.F3)
#define bitdelay 116 // 116 for 9600//it has to be 104 but when i assign 116 i get 104 uc delay , verified in oscilloscope.
#define DataBitCount 8
void main(void) {
ANSEL = 0;
GPIO5 = 1;
GPIO4 = 0; // its to debug
TRISAbits.TRISA5 = 0; // GP5 = NC
TRISAbits.TRISA4 = 0; // GP5 = NC
//T2CON = 0b00001100;
PIN_SER_OUT = 1; // make stop bit
__delay_us(bitdelay);
while(1){
__delay_ms(20);
send_serial_message();
GPIO4 = ~GPIO4;
}
//asm{CLRWDT}
return;
}
void send_serial_message(void)
{
// send message and number to serial port
send_serial_byte(0x64); // send ascii text
send_string("hello world"); send_serial_byte(0x0d);
send_serial_byte(0x0d);
// serial_int_char(3453);
send_serial_byte('c');
}
//---------------------------------------------------------
void serial_int_char(int i)
{
int k;
char a[5];
sprintf (a,"%d",i);
for(k=0;k<4;k++)
{
send_serial_byte(a[k]);
__delay_ms(20);
}
}
void send_string(char *str)
{
while(*str!='\0')
send_serial_byte(*str++);
}
void send_serial_byte(unsigned char data)
{
// unsigned char i;
//i=8; // 8 data bits to send
GPIO4 = ~GPIO4;
PIN_SER_OUT = 0; // make start bit
__delay_us(bitdelay);
for(unsigned char i =0; i<DataBitCount;i++){
GPIO4 = ~GPIO4;
if(((data>>i)&0x01)==0x01){
PIN_SER_OUT = 1;
}
else
PIN_SER_OUT = 0;
__delay_us(bitdelay);
}
GPIO4 = ~GPIO4;
PIN_SER_OUT = 1; // make stop bit
__delay_us(bitdelay);
}
//---------------------------------------------------------[/CODE]
Last edited: