code
code
* File: newmain.c
* Author: kumari.sd
*/
#include <xc.h>
#include <xc.h>
#include <pic18f25k80.h>
// CONFIG1L
#pragma config RETEN = OFF // VREG Sleep Enable bit (Ultra low-power regulator is Disabled
(Controlled by REGSLP bit))
#pragma config INTOSCSEL = HIGH // LF-INTOSC Low-power Enable bit (LF-INTOSC in High-power
mode during Sleep)
#pragma config SOSCSEL = DIG // SOSC Power Selection and mode Configuration bits (Digital
(SCLKI) mode)
// CONFIG1H
#pragma config IESO = OFF // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L
#pragma config BOREN = OFF // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORPWR = ZPBORMV // BORMV Power level (ZPBORMV instead of BORMV is
selected)
// CONFIG2H
#pragma config WDTEN = OFF // Watchdog Timer (WDT disabled in hardware; SWDTEN bit
disabled)
// CONFIG3H
#pragma config CANMX = PORTB // ECAN Mux bit (ECAN TX and RX pins are located on RB2 and
RB3, respectively)
//#pragma config T0CKMX = PORTB // Timer0 Clock Input Mux bit (Timer0 gets its clock input from
the RB5/T0CKI pin on 64-pin packages)
//#pragma config T3CKMX = PORTG // Timer3 Clock Input Mux bit (Timer3 gets its clock input from
the RG2/T3CKI pin on 64-pin packages)
#pragma config MSSPMSK = MSK7 // MSSP address masking (7 Bit address masking mode)
#pragma config MCLRE = OFF // Master Clear Enable (MCLR Disabled, RE3 Enabled)
// CONFIG4L
#pragma config BBSIZ = BB2K // Boot Block Size (2K word Boot Block size)
// CONFIG5L
// CONFIG5H
// CONFIG6L
// CONFIG6H
// CONFIG7L
// CONFIG7H
void ext_interrupt(void);
#define I2C_WRITE 0
#define I2C_READ 1
unsigned int j = 0;
void i2c_Init(void)
// Master 100KHz
TRISCbits.TRISC4=1;
SSPSTAT |= 0x80; /* Slew rate disabled */
SSPCON1 = 0x28; /* SSPEN = 1, I2C Master mode, clock = FOSC/(4 * (SSPADD + 1)) */
TRISCbits.TRISC2=0;
PORTCbits.RC2=0;
// SSP1CON2 = 0x00;
// SSP1CON3bits.SDAHT = 1;
// SSP1ADD = 39;
void i2c_Wait(void){
i2c_Wait();
SEN=1;
void i2c_Restart(void){
i2c_Wait();
RSEN=1;
void i2c_Stop(void)
i2c_Wait();
PEN=1;
i2c_Wait();
SSPBUF = data;
}
// i2c_Address - Sends Slave Address and Read/Write mode
l_address=address<<1;
l_address+=mode;
i2c_Wait();
SSPBUF = l_address;
i2c_Wait();
RCEN=1;
i2c_Wait();
i2cReadData = SSPBUF;
i2c_Wait();
TXREG2= Byte;
return RCREG2;
while(*st)
SendByteSerially(*st++);
}
if (number==0)
*( ascii_number)='0';
*( ascii_number+1)='\0';
else
while (temp_int)
temp_int/=10;
length++;
for (position=length;position>0;position--)
number /= 10;
}
void UART1_put_int(unsigned int number)
char ascii_number[ 11 ];
SendStringSerially( ascii_number ) ;
#define ACQ_US_DELAY 5
#define IN 1
#define OUT 0
#define HIGH 1
#define LOW 0
i2c_Restart(); // Restart
// read_byte1 = i2c_Read(1);
data= i2c_Read(1);
data <<= 8;
data |= i2c_Read(0);
i2c_Stop();
void main(void) {
RCSTA2=0b10010000;// TX Pin
BAUDCON1=0b00001000;
SPBRG2=25; //51
T1CON=0X00;
TMR1H=0;
TMR1L=0;
PIE3 = 0b00110000;
//i2c_Init();
SendStringSerially("Device Id:");
//devid=i2c_FDC_read_2(0x7f);
// UART1_put_int(devid);
// SendStringSerially("\n \r");
while(1)
SendStringSerially("ADC:");
//UART1_put_int(a);
//SendByteSerially('a');
//SendByteSerially('\r');
//SendByteSerially('\n');
/*if(RC0_bit == 0)
// while(MyButton == LOW)
UART1_put_int(lh);
SendStringSerially("\r \n");
//while(MyButton == HIGH)
UART1_put_int(ll);
SendStringSerially("\r \n");
*/
// ll=PORTCbits.RC7;
// SendStringSerially("LL= ");
//UART1_put_int(ll);
// SendStringSerially("\r \n");