|
|
View previous topic :: View next topic |
Author |
Message |
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
PIC16F1947 |
Posted: Tue Jan 24, 2012 11:16 am |
|
|
Hi Everyone,
I am using PIC16F1947 MCU.
CCS PCWHD Version 4.118 compiler.
I am facing lot of problems with this version.
When I add I2C routine in code, cpu get reset.
It may be because of stack overflow.
Please guide me if someone has information?
Thanks in advance......... |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Tue Jan 24, 2012 11:36 am |
|
|
you'll need to post a short compilable program that replicates the issue and post it here using the code tags (not the quote ones). That way you can get some better help. |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
|
Posted: Wed Jan 25, 2012 1:51 am |
|
|
Attaching not working code:
Code: |
#include "16F1947.h"
#fuses HS,NOWDT,PUT,BROWNOUT,NODEBUG,NOLVP,PLL_SW
#use delay (clock=11.0592MHZ)
#define SEL1 PIN_A0
#define SEL2 PIN_A1
#define SEL3 PIN_A2
#define SEL4 PIN_A3
#define SEL5 PIN_A4
#define SEL6 PIN_A5
#define SEL7 PIN_C2
#define SEL8 PIN_C3
#define SEL9 PIN_C4
#define SEL10 PIN_C5
#define SEL11 PIN_G3
#define KEY1 PIN_F0
#define KEY2 PIN_F1
#define KEY3 PIN_F2
#define KEY4 PIN_F3
#define ADC_DATA PIN_B0
#define SELA PIN_B1
#define SELB PIN_B2
#define SELC PIN_B3
#define SHUTDOWN PIN_B4
#define MODEM_ENABLE PIN_B5
#define BUZZ PIN_G0
#define ADC_ADDR 0xD0
#define EEPROM_ADDRESS WORD
#define EEPROM_SIZE 65535
#locate TMR1L = 0x16
#locate TMR1H = 0x17
#use rs232(STREAM = WLM,baud = 9600,RCV = PIN_C7,XMIT = PIN_C6,bits = 8,parity = N,stop = 0,UART1)// for data transfer between Wireless Modem & CPU
#use rs232(STREAM = USB,baud = 1200,RCV = PIN_G2,XMIT = PIN_G1,bits = 8,parity = N,stop = 0,FORCE_SW)// for data transfer between CPU & USB
#use i2c(master, sda=PIN_C1, scl=PIN_C0,fast = 10000,FORCE_SW)
int8 ucHexDisp[8];
int8 ucSevenDisp[5];
int8 ucCount = 0;
int16 uiTimeCounter=0;
int8 ucOute,ucOutd;
int8 ucTempCount1 = 0;
int8 i,ucKey = 0;
int1 FlagSec = 0;
//DISPLAY LOOKUP TABLE FOR 0-9 & A-Z(CAPITAL)
const int16 Alpha_Num_Seg[11]={0xFFC0,0xFFF9,0xFBA4,0xFBB0,0xFB99,0xFB92,0xFB82,0xDDFE,0xFB80,0xFB90};
const int16 Alpha_Seg[27] = {0xFB88,0xEAF0,0xFFC6,0xEEF0,0xFB86,0xFB8E,0xFBC2,0xFB89,0xEEF6,0xFFE1,0xF58F,0xFFC7,0xFD49,0xF749,0xFFC0,0xFB8C,0xF7C0,0xF38C,0xFB72,0xEEFE,0xFFC1,0xDDCF,0xD7C9,0xD57F,0xED7F,0xDDF6,0xFFFF};
const int8 Seven_Num_Seg[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
const int8 Seven_Seg[27] = {0x88,0x83,0xC6,0xA1,0x86,0x8E,0xC2,0x89,0xFB,0xF1,0x8F,0xC7,0xAA,0xAB,0xA3,0x8C,0x98,0xAF,0x92,0x87,0xC1,0xE3,0x95,0xFF,0x91,0xB6};
//unsigned char Seven_DSeg[43]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF,0x89,0xFB,0xF1,0x8F,0xC7,0xAA,0xAB,0xA3,0x8C,0x98,0xAF,0x92,0x87,0xF3,0xFF,0xFF,0xFF,0x91,0xFF};
int1 FlagTemp = 0;
unsigned int8 ucSec;
unsigned int8 ucMin;
unsigned int8 ucHour;
unsigned int8 ucDate;
unsigned int8 ucMonth;
unsigned int8 ucYear;
unsigned int8 ucDow;
signed int16 adc_in;
int8 byte0,byte1,conf,Ack;
int16 uiCountDebounce = 0;
//---------------------------------------------------------------EEPROM Program----------------------------------------------------------//
BOOLEAN ext_eeprom_ready()
{
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xa0); // then the device is ready.
i2c_stop();
return !ack;
}
void write_ext_eeprom(int16 address, BYTE data)
{
while(!ext_eeprom_ready())
{
//restart_wdt();
};
i2c_start();
i2c_write(0xa0);
i2c_write(((address>>8)&0x00FF));
i2c_write((address&0x00FF));
i2c_write(data);
i2c_stop();
//restart_wdt();
}
BYTE read_ext_eeprom(int16 address)
{
BYTE data;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(((address>>8) & 0x00FF));
i2c_write((address & 0x00FF));
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
//restart_wdt();
return(data);
}
void write_ext_eeprom_word(int16 address,int16 data)
{
int8 ucLSB,ucMSB;
ucLSB = (data & 0x00FF);
ucMSB = ((data >> 8)& 0x00FF);
write_ext_eeprom(address,ucMSB);
write_ext_eeprom((address+1),ucLSB);
//restart_wdt();
}
int16 read_ext_eeprom_word(int16 address)
{
int8 ucLSB,ucMSB;
int16 data;
ucMSB = read_ext_eeprom(address);
ucLSB = read_ext_eeprom(address+1);
data = ucMSB;
data = data << 8;
data = data | (0x00FF & ucLSB);
//restart_wdt();
return(data);
}
//----------------------------------------------------- EEPROM Program End -----------------------------------------------------//
//----------------------------------------------------- RTC Program ------------------------------------------------------------//
BYTE bin2bcd(int8 binary_value)
{
int8 temp;
int8 retval;
temp = binary_value;
retval = 0;
while(TRUE)
{
// Get the tens digit by doing multiple subtraction
// of 10 from the binary value.
if(temp >= 10)
{
temp -= 10;
retval += 0x10;
}
else // Get the ones digit by adding the remainder.
{
retval += temp;
break;
}
}
//restart_wdt();
return(retval);
}
// Input range - 00 to 99.
int8 bcd2bin(int8 bcd_value)
{
int8 temp;
temp = bcd_value;
// Shifting upper digit right by 1 is same as multiplying by 8.
temp >>= 1;
// Isolate the bits for the upper digit.
temp &= 0x78;
// Now return: (Tens * 8) + (Tens * 2) + Ones
//restart_wdt();
return(temp + (temp >> 2) + (bcd_value & 0x0f));
}
void ds1307_init(void)
{
int8 j;
int8 ucTemp = 0;
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_start();
i2c_write(0xD1); // RD from RTC
ucTemp = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
i2c_stop();
ucTemp &= 0x7F;
for(j=0;j<10;j++);
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x00); // REG 0
i2c_write(bin2bcd(ucTemp)); // Start oscillator with current "seconds value
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x02); // REG 0
i2c_start();
i2c_write(0xD1); // RD from RTC
ucTemp = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
i2c_stop();
ucTemp &= 0x3F;
for(j=0;j<10;j++);
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x02); // REG 0
i2c_write(bin2bcd(ucTemp)); // Start oscillator with current "seconds value
i2c_start();
i2c_write(0xD0); // WR to RTC
i2c_write(0x07); // Control Register
i2c_write(0x10); // Enable squarewave output pin
i2c_stop();
//restart_wdt();
}
void ds1307_set_date_time(void)
{
ucSec &= 0x7F;
ucHour &= 0x3F;
i2c_start();
i2c_write(0xD0); // I2C write address
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_write(bin2bcd(ucSec)); // REG 0
i2c_write(bin2bcd(ucMin)); // REG 1
i2c_write(bin2bcd(ucHour)); // REG 2
i2c_write(bin2bcd(ucDow)); // REG 3
i2c_write(bin2bcd(ucDate)); // REG 4
i2c_write(bin2bcd(ucMonth)); // REG 5
i2c_write(bin2bcd(ucYear)); // REG 6
i2c_write(0x00); // REG 7 - Enable squarewave output pin
i2c_write('S'); // REG 8 - CheckMark
i2c_write('C'); // REG 9 - CheckMark
i2c_write('V'); // REG A - CheckMark
i2c_stop();
//restart_wdt();
}
void ds1307_get_date(void)
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x03); // Start at REG 3 - Day of week
i2c_start();
i2c_write(0xD1);
ucDow = bcd2bin(i2c_read() & 0x7f); // REG 3
ucDate = bcd2bin(i2c_read() & 0x3f); // REG 4
ucMonth = bcd2bin(i2c_read() & 0x1f); // REG 5
ucYear = bcd2bin(i2c_read(0)); // REG 6
i2c_stop();
//restart_wdt();
}
void ds1307_get_time(void)
{
i2c_start();
i2c_write(0xD0);
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_start();
i2c_write(0xD1);
ucSec = bcd2bin(i2c_read() & 0x7f);
ucMin = bcd2bin(i2c_read() & 0x7f);
ucHour = bcd2bin(i2c_read(0) & 0x3f);
i2c_stop();
//restart_wdt();
}
int1 ds1307_get_date_time(void)
{
int8 ucTempT;
//int1 FlagTemp=0;
i2c_start();
i2c_write(0xD0);
i2c_write(0x00); // Start at REG 0 - Seconds
i2c_start();
i2c_write(0xD1);
ucSec = bcd2bin(i2c_read() & 0x7f);
ucMin = bcd2bin(i2c_read() & 0x7f);
ucHour = bcd2bin(i2c_read() & 0x3f);
ucDow = bcd2bin(i2c_read() & 0x7f); // REG 3
ucDate = bcd2bin(i2c_read() & 0x3f); // REG 4
ucMonth = bcd2bin(i2c_read() & 0x1f); // REG 5
ucYear = bcd2bin(i2c_read()); // REG 6
ucTempT = i2c_read(); // REG 7
ucTempT = i2c_read(); // REG 8
if(ucTempT == 'S')
{
ucTempT = i2c_read(); // REG 9
if(ucTempT == 'C')
{
ucTempT = i2c_read(); // REG A
if(ucTempT == 'V')
{
//FlagTemp = 0;
ucTempT = i2c_read(0);
i2c_stop();
//restart_wdt();
return(0);
}
}
}
ucTempT = i2c_read(0);
i2c_stop();
//restart_wdt();
return(1);
}
//------------------------------------------------ RTC Program End --------------------------------------------------//
//------------------------------------------------ ADC MCP3422 --------------------------------------------------//
void InitADC(void)
{
i2c_start();
//
// MCP3422 ADDRESS BYTE - MSB first
//
// 1 - 1 - 0 - 1 - A2 - A1 - A0 - R/W
//
//
// Part Number - Address Option - Code on package
// MCP3422A0T-E/CH - A0 (000) - CANN
// MCP3422A1T-E/CH - A1 (001) - CBNN
// MCP3422A2T-E/CH - A2 (010) - CCNN
// MCP3422A3T-E/CH - A3 (011) - CDNN
// MCP3422A4T-E/CH - A4 (100) - CENN
// MCP3422A5T-E/CH - A5 (101) - CFNN
// MCP3422A6T-E/CH - A6 (110) - CGNN
// MCP3422A7T-E/CH - A7 (111) - CHNN
//
// Change the address depending on your ADC, check the code on package
// or the invoice from your supplier
//
// 1101XXX0
//
Ack = i2c_write( ADC_ADDR & 0xFE ); // Write mode
//
// MCP3421 CONFIGURATION REGISTER - MSB first
// RDY - C1 - C0 - O/C - S1 - S0 - G1 - G0
//
//Ack = i2c_write( 0b00010000 ); // Continuous conversion - 12bit - PGA = 1V/V
Ack = i2c_write( 0b00011000 ); // Continuous conversion - 16bit - PGA = 1V/V
i2c_stop();
}
//
// Continuous conversion and display on LCD
//
void GetADC(void)
{
int8 i;
i2c_start();
Ack = i2c_write(ADC_ADDR | 0x01); // Send address of MCP3422
for(i=0;i<250;i++);
//
// NOTE: Don't ack the last byte read
//
byte0 = i2c_read( 1 ); // read first byte and send ack
byte1 = i2c_read( 1 ); // read second byte and send ack
// byte2 = i2c_read( 1 ); // read third byte and send ack
conf = i2c_read( 0 ); // read configuration byte - optional
i2c_stop();
//
// Build a int32 from the 3 bytes read
//
// byte0 &= 0b00000001; // Mask unused bits, probably not neccesary
// adc_in = byte0;
// adc_in <<= 8;
// adc_in += byte1;
if(!(conf & 0x80))
{
adc_in = byte0;
adc_in <<= 8;
adc_in = adc_in & 0xFF00;
adc_in += byte1;
adc_in += 3000; //Software Offset
}
}
//------------------------------------------------ ADC MCP3422 End --------------------------------------------------//
void HexData(unsigned int8 ucTempCount)
{
if((ucHexDisp[ucTempCount] >= 'A') && (ucHexDisp[ucTempCount] <= 'Z'))
{
ucOute = (int8)(Alpha_Seg[ucHexDisp[ucTempCount] - 'A']);
ucOutd = (int8)((Alpha_Seg[ucHexDisp[ucTempCount] - 'A']) >> 8);
}
else
if((ucHexDisp[ucTempCount] >= '0') && (ucHexDisp[ucTempCount] <= '9'))
{
ucOute = (int8)(Alpha_Num_Seg[ucHexDisp[ucTempCount] - '0']);
ucOutd = (int8)((Alpha_Num_Seg[ucHexDisp[ucTempCount] - '0']) >> 8);
}
else
if(ucHexDisp[ucTempCount] == '-')
{
ucOute = 0xBF;
ucOutd = 0xFB;
}
else
{
ucOute = ucHexDisp[ucTempCount];
ucOutd = ucHexDisp[ucTempCount];
}
}
void SevenData(unsigned int8 ucTempCount)
{
if((ucSevenDisp[ucTempCount] >= 'A') && (ucSevenDisp[ucTempCount] <= 'Z'))
{
ucOute = (Seven_Seg[ucSevenDisp[ucTempCount] - 'A']);
}
else
if((ucSevenDisp[ucTempCount] >= '0') && (ucSevenDisp[ucTempCount] <= '9'))
{
ucOute = (Seven_Num_Seg[ucSevenDisp[ucTempCount] - '0']);
}
else
{
ucOute = Seven_Seg[ucSevenDisp[ucTempCount]];
}
if((ucSevenDisp[ucTempCount+1] >= 'A') && (ucSevenDisp[ucTempCount+1] <= 'Z'))
{
ucOutd = (Seven_Seg[ucSevenDisp[ucTempCount+1] - 'A']);
}
else
if((ucSevenDisp[ucTempCount+1] >= '0') && (ucSevenDisp[ucTempCount+1] <= '9'))
{
ucOutd = (Seven_Num_Seg[ucSevenDisp[ucTempCount+1] - '0']);
}
else
{
ucOutd = Seven_Seg[ucSevenDisp[ucTempCount+1]];
}
}
#int_timer1
void timer1_isr(void)
{
disable_interrupts(int_timer1);
clear_interrupt(int_timer1);
ucCount++;
if(ucCount>100)
{
ucCount=0;
}
if((!input(KEY1))) uiCountDebounce++;
else
if((!input(KEY2))) uiCountDebounce++;
else
if((!input(KEY3))) uiCountDebounce++;
else
if((!input(KEY4))) uiCountDebounce++;
else uiCountDebounce = 0;
if(uiCountDebounce > 50)
{
uiCountDebounce = 0;
if((!input(KEY1))) ucKey = 1;
else
if((!input(KEY2))) ucKey = 2;
else
if((!input(KEY3))) ucKey = 3;
else
if((!input(KEY4))) ucKey = 4;
}
if(!FlagSec)
{
uiTimeCounter++;
if(uiTimeCounter >1000)
{
FlagSec = 1;
FlagTemp=1;
uiTimeCounter=0;
}
}
switch(ucCount)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
HexData(ucCount);
break;
case 8:
SevenData(0);
break;
case 9:
SevenData(2);
break;
case 10:
ucOute = ucSevenDisp[4];
ucOutd = 0xFF;
break;
}
switch(ucCount)
{
case 0:
output_high(SEL11);
output_e(ucOute);
output_d(ucOutd);
output_low(SEL1) ;
break;
case 1:
output_high(SEL1) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL2) ;
break;
case 2:
output_high(SEL2) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL3) ;
break;
case 3:
output_high(SEL3) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL4) ;
break;
case 4:
output_high(SEL4) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL5) ;
break;
case 5:
output_high(SEL5) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL6) ;
break;
case 6:
output_high(SEL6) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL7) ;
break;
case 7:
output_high(SEL7) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL8) ;
break;
case 8:
output_high(SEL8) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL9) ;
break;
case 9:
output_high(SEL9) ;
output_e(ucOute);
output_d(ucOutd);
output_low(SEL10);
break;
case 10:
output_high(SEL10);
output_e(ucOute);
output_d(ucOutd);
output_low(SEL11);
break;
}
//set_timer1(0xF52D);
TMR1H = 0xF5;
TMR1L = 0x2D;
enable_interrupts(int_timer1);
}
void main(void)
{
//setup_oscillator(OSC_16MHz);
delay_ms(100);
set_tris_a(0x00);
set_tris_b(0xC0);
set_tris_c(0x80);
set_tris_d(0x00);
set_tris_e(0x00);
set_tris_f(0xFF);
set_tris_g(0x04);
//output_d(0xFB);
//output_e(0x80);
output_high(SEL1);
output_high(SEL2);
output_high(SEL3);
output_high(SEL4);
output_high(SEL5);
output_high(SEL6);
output_high(SEL7);
output_high(SEL8);
output_high(SEL9);
output_high(SEL10);
output_high(SEL11);
output_high(BUZZ);
output_low(SELA);
output_low(SELB);
output_low(SELC);
output_low(SHUTDOWN);
output_low(MODEM_ENABLE);
output_float(PIN_C0);
output_float(PIN_C1);
ucSec = 11;
ucMin = 11;
ucHour = 11;
ucDow = 1;
ucDate = 11;
ucMonth = 11;
ucYear = 11;
/*
ds1307_init();
ds1307_set_date_time();
*/
InitADC();
//Timer1 Registers Prescaler= 1 - TMR1 Preset = 62765 period=1 ms
TMR1H = 0xF5;
TMR1L = 0x2D;
//set_timer1(0xF52D); ////1ms
setup_timer_1(T1_FOSC|T1_DIV_BY_1);
clear_interrupt(int_timer1);
enable_interrupts(int_timer1);
//enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
ucTempCount1 = 0;
disable_interrupts(INT_TIMER1);
delay_ms(20);
fprintf(WLM,"Shambhu C. Vetal");
delay_ms(20);
enable_interrupts(INT_TIMER1);
while(1)
{
if(FlagSec)
{
FlagSec = 0;
disable_interrupts(INT_TIMER1);
GetADC();
ucHexDisp[4] = (adc_in % 10) + 0x30; adc_in = adc_in / 10;
ucHexDisp[3] = (adc_in % 10) + 0x30; adc_in = adc_in / 10;
ucHexDisp[2] = (adc_in % 10) + 0x30; adc_in = adc_in / 10;
ucHexDisp[1] = (adc_in % 10) + 0x30; adc_in = adc_in / 10;
ucHexDisp[0] = (adc_in % 10) + 0x30;
/* if(!ds1307_get_date_time())
{
ucHexDisp[0] = ((ucHour / 10) % 10)+ 0x30;
ucHexDisp[1] = (ucHour % 10) + 0x30;
ucHexDisp[2] = '-';
ucHexDisp[3] = ((ucMin / 10) % 10) + 0x30;
ucHexDisp[4] = (ucMin % 10) + 0x30;
ucHexDisp[5] = '-';
ucHexDisp[6] = ((ucSec / 10) % 10) + 0x30;
ucHexDisp[7] = (ucSec % 10) + 0x30;
}
else
{
ucHexDisp[0] = 'R';
ucHexDisp[1] = 'T';
ucHexDisp[2] = 'C';
ucHexDisp[3] = '-';
ucHexDisp[4] = 'E';
ucHexDisp[5] = 'R';
ucHexDisp[6] = 'O';
ucHexDisp[7] = 'R';
}
*/
//fprintf(WLM,"$$$$1234");
//delay_ms(20);
enable_interrupts(INT_TIMER1);
/*for(i=0;i<8;i++)
{
ucHexDisp[i] = ucTempCount1 + 'A';
}*/
for(i=0;i<4;i++)
{
ucSevenDisp[i] = ucKey + 'A';
}
ucTempCount1++;
if(ucTempCount1 > 25)
{
ucTempCount1 = 0;
}
}
}
}
|
When I add i2c routine for rtc/memory/adc, cpu get reset. _________________ shambhuvetal |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Wed Jan 25, 2012 5:04 am |
|
|
Look at the sixth word in Jeremiah's suggestion. Do you think this qualifies....
Seriously, this is part of debugging. If you have a problem like you are describing, then use an absolute minimum program, and try talking to just one I2C device. If the problem doesn't then show, add another.
As it stands, _you_ need to cut the code down, and in doing so, you may well find the problem. If not, you then have something small enough that we can help. |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
16f1947 problem |
Posted: Wed Jan 25, 2012 6:13 am |
|
|
Code works fine when it is in small pieces.
e.g. when i add only RTC , it works fine.
when i add RTC+EEPROM,it works fine.
but when i add more than this CPU reset.
then it doesn't matter wheither code is of ADC or keypad or simple display function.
i think it's problem to jump next code bank.
adding list file for same:
ROM used: 2174 words (13%)
Largest free fragment is 2048
RAM used: 49 (5%) at main() level
67 (7%) worst case
Stack: 5 worst case (2 in main + 3 for interrupts)
*
0000: MOVLP 08
0001: GOTO 000
0002: NOP
*
0004: CLRF 03
0005: CLRF 0A
0006: MOVLB 00
0007: MOVF 77,W
0008: MOVWF 20
0009: MOVF 78,W
000A: MOVWF 21
000B: MOVF 79,W
000C: MOVWF 22
000D: MOVF 7A,W
000E: MOVWF 23
000F: CLRF 05
0010: MOVLW 91
0011: MOVWF 04
0012: BTFSS 00.0
0013: GOTO 016
0014: BTFSC 11.0
0015: GOTO 01F
0016: MOVF 20,W
0017: MOVWF 77
0018: MOVF 21,W
0019: MOVWF 78
001A: MOVF 22,W
001B: MOVWF 79
001C: MOVF 23,W
001D: MOVWF 7A
001E: RETFIE
001F: MOVLP 00
0020: GOTO 141
.................... #include "16F1947.h"
.................... //////// Standard Header file for the PIC16F1947 device ////////////////
.................... #device PIC16F1947
.................... #list
....................
....................
.................... #fuses HS,NOWDT,PUT,BROWNOUT,NODEBUG,NOLVP,PLL_SW
.................... #use delay (clock=11.0592MHZ)
*
0346: MOVLW 20
0347: MOVWF 05
0348: MOVLW 2A
0349: MOVWF 04
034A: MOVF 00,W
034B: BTFSC 03.2
034C: GOTO 35A
034D: MOVLW 03
034E: MOVWF 78
034F: CLRF 77
0350: DECFSZ 77,F
0351: GOTO 350
0352: DECFSZ 78,F
0353: GOTO 34F
0354: MOVLW 95
0355: MOVWF 77
0356: DECFSZ 77,F
0357: GOTO 356
0358: DECFSZ 00,F
0359: GOTO 34D
035A: RETURN
....................
.................... #define SEL1 PIN_A0
.................... #define SEL2 PIN_A1
.................... #define SEL3 PIN_A2
.................... #define SEL4 PIN_A3
.................... #define SEL5 PIN_A4
.................... #define SEL6 PIN_A5
.................... #define SEL7 PIN_C2
.................... #define SEL8 PIN_C3
.................... #define SEL9 PIN_C4
.................... #define SEL10 PIN_C5
.................... #define SEL11 PIN_G3
....................
.................... #define KEY1 PIN_F0
.................... #define KEY2 PIN_F1
.................... #define KEY3 PIN_F2
.................... #define KEY4 PIN_F3
....................
.................... #define ADC_DATA PIN_B0
.................... #define SELA PIN_B1
.................... #define SELB PIN_B2
.................... #define SELC PIN_B3
.................... #define SHUTDOWN PIN_B4
.................... #define MODEM_ENABLE PIN_B5
....................
.................... #define BUZZ PIN_G0
....................
.................... #define ADC_ADDR 0xD0
.................... #define EEPROM_ADDRESS WORD
.................... #define EEPROM_SIZE 65535
....................
.................... #use rs232(STREAM = WLM,baud = 9600,RCV = PIN_C7,XMIT = PIN_C6,bits = 8,parity = N,stop = 0)// for data transfer between Wireless Modem & CPU
.................... #use rs232(STREAM = USB,baud = 1200,RCV = PIN_G2,XMIT = PIN_G1,bits = 8,parity = N,stop = 0,FORCE_SW)// for data transfer between CPU & USB
*
05C9: MOVLB 06
05CA: BCF 0D.1
05CB: MOVLB 07
05CC: BCF 0D.1
05CD: MOVLW 08
05CE: MOVWF 78
05CF: GOTO 5D0
05D0: NOP
05D1: BSF 78.7
05D2: GOTO 5ED
05D3: BCF 78.7
05D4: MOVLB 00
05D5: RRF 4D,F
05D6: MOVLB 02
05D7: BTFSS 03.0
05D8: GOTO 5DC
05D9: MOVLB 07
05DA: BSF 0D.1
05DB: MOVLB 02
05DC: BTFSC 03.0
05DD: GOTO 5E1
05DE: MOVLB 07
05DF: BCF 0D.1
05E0: MOVLB 02
05E1: BSF 78.6
05E2: GOTO 5EE
05E3: BCF 78.6
05E4: DECFSZ 78,F
05E5: GOTO 5E7
05E6: GOTO 5E9
05E7: MOVLB 07
05E8: GOTO 5D4
05E9: GOTO 5EA
05EA: NOP
05EB: MOVLB 07
05EC: BSF 0D.1
05ED: MOVLB 02
05EE: MOVLW 02
05EF: MOVWF 77
05F0: CLRF 04
05F1: DECFSZ 04,F
05F2: GOTO 5F1
05F3: DECFSZ 77,F
05F4: GOTO 5F0
05F5: MOVLW F6
05F6: MOVWF 04
05F7: DECFSZ 04,F
05F8: GOTO 5F7
05F9: GOTO 5FA
05FA: NOP
05FB: BTFSS 78.7
05FC: GOTO 5FF
05FD: MOVLB 07
05FE: GOTO 5D3
05FF: BTFSC 78.6
0600: GOTO 5E3
0601: MOVLB 00
0602: RETURN
.................... #use i2c(master, sda=PIN_C1, scl=PIN_C0,fast = 10000,FORCE_SW)
*
035B: MOVLW 08
035C: MOVWF 78
035D: MOVLW 29
035E: MOVWF 77
035F: DECFSZ 77,F
0360: GOTO 35F
0361: MOVLB 02
0362: BCF 0E.0
0363: MOVLB 01
0364: BCF 0E.0
0365: MOVLW 28
0366: MOVWF 77
0367: DECFSZ 77,F
0368: GOTO 367
0369: MOVLB 00
036A: RLF 4D,F
036B: MOVLB 02
036C: BCF 0E.1
036D: BTFSS 03.0
036E: GOTO 372
036F: MOVLB 01
0370: BSF 0E.1
0371: MOVLB 02
0372: BTFSC 03.0
0373: GOTO 377
0374: MOVLB 01
0375: BCF 0E.1
0376: MOVLB 02
0377: MOVLB 01
0378: BSF 0E.0
0379: MOVLB 00
037A: BTFSS 0E.0
037B: GOTO 37A
037C: DECFSZ 78,F
037D: GOTO 35D
037E: MOVLW 29
037F: MOVWF 77
0380: DECFSZ 77,F
0381: GOTO 380
0382: MOVLB 02
0383: BCF 0E.0
0384: MOVLB 01
0385: BCF 0E.0
0386: NOP
0387: BSF 0E.1
0388: MOVLW 28
0389: MOVWF 77
038A: DECFSZ 77,F
038B: GOTO 38A
038C: MOVLW 28
038D: MOVWF 77
038E: DECFSZ 77,F
038F: GOTO 38E
0390: BSF 0E.0
0391: MOVLB 00
0392: BTFSS 0E.0
0393: GOTO 392
0394: CLRF 78
0395: MOVLW 28
0396: MOVWF 77
0397: DECFSZ 77,F
0398: GOTO 397
0399: BTFSC 0E.1
039A: BSF 78.0
039B: MOVLB 02
039C: BCF 0E.0
039D: MOVLB 01
039E: BCF 0E.0
039F: MOVLB 02
03A0: BCF 0E.1
03A1: MOVLB 01
03A2: BCF 0E.1
03A3: MOVLB 00
03A4: RETURN
03A5: MOVLW 08
03A6: MOVWF 4D
03A7: MOVF 77,W
03A8: MOVWF 4E
03A9: MOVLB 01
03AA: BSF 0E.1
03AB: MOVLW 28
03AC: MOVWF 77
03AD: DECFSZ 77,F
03AE: GOTO 3AD
03AF: BSF 0E.0
03B0: MOVLB 00
03B1: BTFSS 0E.0
03B2: GOTO 3B1
03B3: BTFSC 0E.1
03B4: BSF 03.0
03B5: BTFSS 0E.1
03B6: BCF 03.0
03B7: RLF 78,F
03B8: MOVLW 29
03B9: MOVWF 77
03BA: DECFSZ 77,F
03BB: GOTO 3BA
03BC: MOVLB 01
03BD: BCF 0E.0
03BE: MOVLB 02
03BF: BCF 0E.0
03C0: MOVLB 00
03C1: DECFSZ 4D,F
03C2: GOTO 3A9
03C3: MOVLB 01
03C4: BSF 0E.1
03C5: MOVLW 28
03C6: MOVWF 77
03C7: DECFSZ 77,F
03C8: GOTO 3C7
03C9: MOVLB 02
03CA: BCF 0E.1
03CB: MOVLB 00
03CC: MOVF 4E,W
03CD: BTFSC 03.2
03CE: GOTO 3D2
03CF: MOVLB 01
03D0: BCF 0E.1
03D1: MOVLB 00
03D2: NOP
03D3: MOVLB 01
03D4: BSF 0E.0
03D5: MOVLB 00
03D6: BTFSS 0E.0
03D7: GOTO 3D6
03D8: MOVLW 29
03D9: MOVWF 77
03DA: DECFSZ 77,F
03DB: GOTO 3DA
03DC: MOVLB 02
03DD: BCF 0E.0
03DE: MOVLB 01
03DF: BCF 0E.0
03E0: MOVLW 28
03E1: MOVWF 77
03E2: DECFSZ 77,F
03E3: GOTO 3E2
03E4: MOVLB 02
03E5: BCF 0E.1
03E6: MOVLB 01
03E7: BCF 0E.1
03E8: MOVLB 00
03E9: RETURN
....................
.................... int16 uiCountDebounce = 0;
.................... int8 ucKey = 0;
.................... int8 ucHexDisp[8];
.................... int8 ucSevenDisp[5];
.................... int8 ucCount = 0;
.................... int16 uiTimeCounter=0;
.................... int8 ucOute,ucOutd;
....................
.................... int8 ucTempCount1 = 0;
.................... int8 i;
....................
.................... int1 FlagSec = 0;
.................... //DISPLAY LOOKUP TABLE FOR 0-9 & A-Z(CAPITAL)
.................... const int16 Alpha_Num_Seg[11]={0xFFC0,0xFFF9,0xFBA4,0xFBB0,0xFB99,0xFB92,0xFB82,0xDDFE,0xFB80,0xFB90};
.................... const int16 Alpha_Seg[27] = {0xFB88,0xEAF0,0xFFC6,0xEEF0,0xFB86,0xFB8E,0xFBC2,0xFB89,0xEEF6,0xFFE1,0xF58F,0xFFC7,0xFD49,0xF749,0xFFC0,0xFB8C,0xF7C0,0xF38C,0xFB72,0xEEFE,0xFFC1,0xDDCF,0xD7C9,0xD57F,0xED7F,0xDDF6,0xFFFF};
.................... const int8 Seven_Num_Seg[11]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
.................... const int8 Seven_Seg[27] = {0x88,0x83,0xC6,0xA1,0x86,0x8E,0xC2,0x89,0xFB,0xF1,0x8F,0xC7,0xAA,0xAB,0xA3,0x8C,0x98,0xAF,0x92,0x87,0xC1,0xE3,0x95,0xFF,0x91,0xB6};
.................... //unsigned char Seven_DSeg[43]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF,0x89,0xFB,0xF1,0x8F,0xC7,0xAA,0xAB,0xA3,0x8C,0x98,0xAF,0x92,0x87,0xF3,0xFF,0xFF,0xFF,0x91,0xFF};
.................... int1 FlagTemp = 0;
.................... signed int16 adc_in;
.................... int8 byte0,byte1,conf,Ack;
.................... int8 ucTemp2;
.................... unsigned int8 ucSec;
.................... unsigned int8 ucMin;
.................... unsigned int8 ucHour;
.................... unsigned int8 ucDate;
.................... unsigned int8 ucMonth;
.................... unsigned int8 ucYear;
.................... unsigned int8 ucDow;
.................... /*/---------------------------------------------------------------EEPROM Program----------------------------------------------------------//
.................... BOOLEAN ext_eeprom_ready()
.................... {
.................... int1 ack;
.................... i2c_start(); // If the write command is acknowledged,
.................... ack = i2c_write(0xa0); // then the device is ready.
.................... i2c_stop();
.................... return !ack;
.................... }
....................
.................... void write_ext_eeprom(int16 address, BYTE data)
.................... {
.................... while(!ext_eeprom_ready())
.................... {
.................... //restart_wdt();
.................... };
.................... i2c_start();
.................... i2c_write(0xa0);
.................... i2c_write(((address>>8)&0x00FF));
.................... i2c_write((address&0x00FF));
.................... i2c_write(data);
.................... i2c_stop();
.................... //restart_wdt();
.................... }
....................
....................
.................... BYTE read_ext_eeprom(int16 address)
.................... {
.................... BYTE data;
.................... while(!ext_eeprom_ready());
.................... i2c_start();
.................... i2c_write(0xa0);
.................... i2c_write(((address>>8) & 0x00FF));
.................... i2c_write((address & 0x00FF));
.................... i2c_start();
.................... i2c_write(0xa1);
.................... data=i2c_read(0);
.................... i2c_stop();
.................... //restart_wdt();
.................... return(data);
.................... }
....................
.................... void write_ext_eeprom_word(int16 address,int16 data)
.................... {
.................... int8 ucLSB,ucMSB;
.................... ucLSB = (data & 0x00FF);
.................... ucMSB = ((data >> 8)& 0x00FF);
.................... write_ext_eeprom(address,ucMSB);
.................... write_ext_eeprom((address+1),ucLSB);
.................... //restart_wdt();
.................... }
....................
.................... int16 read_ext_eeprom_word(int16 address)
.................... {
.................... int8 ucLSB,ucMSB;
.................... int16 data;
.................... ucMSB = read_ext_eeprom(address);
.................... ucLSB = read_ext_eeprom(address+1);
.................... data = ucMSB;
.................... data = data << 8;
.................... data = data | (0x00FF & ucLSB);
.................... //restart_wdt();
.................... return(data);
.................... }
.................... */
.................... //----------------------------------------------------- RTC Program ------------------------------------------------------------//
.................... BYTE bin2bcd(int8 binary_value)
.................... {
.................... int8 temp;
.................... int8 retval;
....................
.................... temp = binary_value;
*
03FD: MOVF 4C,W
03FE: MOVWF 4D
.................... retval = 0;
03FF: CLRF 4E
....................
.................... while(TRUE)
.................... {
.................... // Get the tens digit by doing multiple subtraction
.................... // of 10 from the binary value.
.................... if(temp >= 10)
0400: MOVF 4D,W
0401: SUBLW 09
0402: BTFSC 03.0
0403: GOTO 409
.................... {
.................... temp -= 10;
0404: MOVLW 0A
0405: SUBWF 4D,F
.................... retval += 0x10;
0406: MOVLW 10
0407: ADDWF 4E,F
.................... }
.................... else // Get the ones digit by adding the remainder.
0408: GOTO 40C
.................... {
.................... retval += temp;
0409: MOVF 4D,W
040A: ADDWF 4E,F
.................... break;
040B: GOTO 40D
.................... }
.................... }
040C: GOTO 400
.................... //restart_wdt();
.................... return(retval);
040D: MOVF 4E,W
040E: MOVWF 78
.................... }
040F: RETURN
....................
....................
.................... // Input range - 00 to 99.
.................... int8 bcd2bin(int8 bcd_value)
.................... {
.................... int8 temp;
....................
.................... temp = bcd_value;
*
03EA: MOVF 4D,W
03EB: MOVWF 4E
.................... // Shifting upper digit right by 1 is same as multiplying by 8.
.................... temp >>= 1;
03EC: BCF 03.0
03ED: RRF 4E,F
.................... // Isolate the bits for the upper digit.
.................... temp &= 0x78;
03EE: MOVLW 78
03EF: ANDWF 4E,F
....................
.................... // Now return: (Tens * 8) + (Tens * 2) + Ones
.................... //restart_wdt();
.................... return(temp + (temp >> 2) + (bcd_value & 0x0f));
03F0: RRF 4E,W
03F1: MOVWF 77
03F2: RRF 77,F
03F3: MOVLW 3F
03F4: ANDWF 77,F
03F5: MOVF 77,W
03F6: ADDWF 4E,W
03F7: MOVWF 4F
03F8: MOVF 4D,W
03F9: ANDLW 0F
03FA: ADDWF 4F,W
03FB: MOVWF 78
.................... }
03FC: RETURN
....................
....................
.................... void ds1307_init(void)
.................... {
*
0410: CLRF 4B
.................... int8 j;
.................... int8 ucTemp = 0;
....................
.................... i2c_start();
0411: MOVLB 01
0412: BSF 0E.1
0413: MOVLW 29
0414: MOVWF 77
0415: DECFSZ 77,F
0416: GOTO 415
0417: BSF 0E.0
0418: MOVLW 28
0419: MOVWF 77
041A: DECFSZ 77,F
041B: GOTO 41A
041C: MOVLB 02
041D: BCF 0E.1
041E: MOVLB 01
041F: BCF 0E.1
0420: MOVLW 29
0421: MOVWF 77
0422: DECFSZ 77,F
0423: GOTO 422
0424: MOVLB 02
0425: BCF 0E.0
0426: MOVLB 01
0427: BCF 0E.0
.................... i2c_write(0xD0); // WR to RTC
0428: MOVLW D0
0429: MOVLB 00
042A: MOVWF 4D
042B: CALL 35B
.................... i2c_write(0x00); // REG 0
042C: CLRF 4D
042D: CALL 35B
.................... i2c_start();
042E: MOVLB 01
042F: BSF 0E.1
0430: MOVLW 29
0431: MOVWF 77
0432: DECFSZ 77,F
0433: GOTO 432
0434: BSF 0E.0
0435: MOVLW 28
0436: MOVWF 77
0437: DECFSZ 77,F
0438: GOTO 437
0439: MOVLB 00
043A: BTFSS 0E.0
043B: GOTO 43A
043C: MOVLB 02
043D: BCF 0E.1
043E: MOVLB 01
043F: BCF 0E.1
0440: MOVLW 29
0441: MOVWF 77
0442: DECFSZ 77,F
0443: GOTO 442
0444: MOVLB 02
0445: BCF 0E.0
0446: MOVLB 01
0447: BCF 0E.0
.................... i2c_write(0xD1); // RD from RTC
0448: MOVLW D1
0449: MOVLB 00
044A: MOVWF 4D
044B: CALL 35B
.................... ucTemp = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
044C: CLRF 77
044D: CALL 3A5
044E: MOVF 78,W
044F: MOVWF 4C
0450: MOVWF 4D
0451: CALL 3EA
0452: MOVF 78,W
0453: MOVWF 4B
.................... i2c_stop();
0454: MOVLB 01
0455: BCF 0E.1
0456: NOP
0457: BSF 0E.0
0458: MOVLB 00
0459: BTFSS 0E.0
045A: GOTO 459
045B: MOVLW 29
045C: MOVWF 77
045D: DECFSZ 77,F
045E: GOTO 45D
045F: GOTO 460
0460: NOP
0461: MOVLB 01
0462: BSF 0E.1
0463: MOVLW 29
0464: MOVWF 77
0465: DECFSZ 77,F
0466: GOTO 465
.................... ucTemp &= 0x7F;
0467: MOVLB 00
0468: BCF 4B.7
....................
.................... for(j=0;j<10;j++);
0469: CLRF 4A
046A: MOVF 4A,W
046B: SUBLW 09
046C: BTFSS 03.0
046D: GOTO 470
046E: INCF 4A,F
046F: GOTO 46A
....................
.................... i2c_start();
0470: MOVLB 01
0471: BSF 0E.1
0472: MOVLW 29
0473: MOVWF 77
0474: DECFSZ 77,F
0475: GOTO 474
0476: BSF 0E.0
0477: MOVLW 28
0478: MOVWF 77
0479: DECFSZ 77,F
047A: GOTO 479
047B: MOVLB 02
047C: BCF 0E.1
047D: MOVLB 01
047E: BCF 0E.1
047F: MOVLW 29
0480: MOVWF 77
0481: DECFSZ 77,F
0482: GOTO 481
0483: MOVLB 02
0484: BCF 0E.0
0485: MOVLB 01
0486: BCF 0E.0
.................... i2c_write(0xD0); // WR to RTC
0487: MOVLW D0
0488: MOVLB 00
0489: MOVWF 4D
048A: CALL 35B
.................... i2c_write(0x00); // REG 0
048B: CLRF 4D
048C: CALL 35B
.................... i2c_write(bin2bcd(ucTemp)); // Start oscillator with current "seconds value
048D: MOVF 4B,W
048E: MOVWF 4C
048F: CALL 3FD
0490: MOVF 78,W
0491: MOVWF 4C
0492: MOVWF 4D
0493: CALL 35B
....................
.................... i2c_start();
0494: MOVLB 01
0495: BSF 0E.1
0496: MOVLW 29
0497: MOVWF 77
0498: DECFSZ 77,F
0499: GOTO 498
049A: BSF 0E.0
049B: MOVLW 28
049C: MOVWF 77
049D: DECFSZ 77,F
049E: GOTO 49D
049F: MOVLB 00
04A0: BTFSS 0E.0
04A1: GOTO 4A0
04A2: MOVLB 02
04A3: BCF 0E.1
04A4: MOVLB 01
04A5: BCF 0E.1
04A6: MOVLW 29
04A7: MOVWF 77
04A8: DECFSZ 77,F
04A9: GOTO 4A8
04AA: MOVLB 02
04AB: BCF 0E.0
04AC: MOVLB 01
04AD: BCF 0E.0
.................... i2c_write(0xD0); // WR to RTC
04AE: MOVLW D0
04AF: MOVLB 00
04B0: MOVWF 4D
04B1: CALL 35B
.................... i2c_write(0x02); // REG 0
04B2: MOVLW 02
04B3: MOVWF 4D
04B4: CALL 35B
.................... i2c_start();
04B5: MOVLB 01
04B6: BSF 0E.1
04B7: MOVLW 29
04B8: MOVWF 77
04B9: DECFSZ 77,F
04BA: GOTO 4B9
04BB: BSF 0E.0
04BC: MOVLW 28
04BD: MOVWF 77
04BE: DECFSZ 77,F
04BF: GOTO 4BE
04C0: MOVLB 00
04C1: BTFSS 0E.0
04C2: GOTO 4C1
04C3: MOVLB 02
04C4: BCF 0E.1
04C5: MOVLB 01
04C6: BCF 0E.1
04C7: MOVLW 29
04C8: MOVWF 77
04C9: DECFSZ 77,F
04CA: GOTO 4C9
04CB: MOVLB 02
04CC: BCF 0E.0
04CD: MOVLB 01
04CE: BCF 0E.0
.................... i2c_write(0xD1); // RD from RTC
04CF: MOVLW D1
04D0: MOVLB 00
04D1: MOVWF 4D
04D2: CALL 35B
.................... ucTemp = bcd2bin(i2c_read(0)); // Read current "seconds" in DS1307
04D3: CLRF 77
04D4: CALL 3A5
04D5: MOVF 78,W
04D6: MOVWF 4C
04D7: MOVWF 4D
04D8: CALL 3EA
04D9: MOVF 78,W
04DA: MOVWF 4B
.................... i2c_stop();
04DB: MOVLB 01
04DC: BCF 0E.1
04DD: NOP
04DE: BSF 0E.0
04DF: MOVLB 00
04E0: BTFSS 0E.0
04E1: GOTO 4E0
04E2: MOVLW 29
04E3: MOVWF 77
04E4: DECFSZ 77,F
04E5: GOTO 4E4
04E6: GOTO 4E7
04E7: NOP
04E8: MOVLB 01
04E9: BSF 0E.1
04EA: MOVLW 29
04EB: MOVWF 77
04EC: DECFSZ 77,F
04ED: GOTO 4EC
.................... ucTemp &= 0x3F;
04EE: MOVLW 3F
04EF: MOVLB 00
04F0: ANDWF 4B,F
....................
.................... for(j=0;j<10;j++);
04F1: CLRF 4A
04F2: MOVF 4A,W
04F3: SUBLW 09
04F4: BTFSS 03.0
04F5: GOTO 4F8
04F6: INCF 4A,F
04F7: GOTO 4F2
....................
.................... i2c_start();
04F8: MOVLB 01
04F9: BSF 0E.1
04FA: MOVLW 29
04FB: MOVWF 77
04FC: DECFSZ 77,F
04FD: GOTO 4FC
04FE: BSF 0E.0
04FF: MOVLW 28
0500: MOVWF 77
0501: DECFSZ 77,F
0502: GOTO 501
0503: MOVLB 02
0504: BCF 0E.1
0505: MOVLB 01
0506: BCF 0E.1
0507: MOVLW 29
0508: MOVWF 77
0509: DECFSZ 77,F
050A: GOTO 509
050B: MOVLB 02
050C: BCF 0E.0
050D: MOVLB 01
050E: BCF 0E.0
.................... i2c_write(0xD0); // WR to RTC
050F: MOVLW D0
0510: MOVLB 00
0511: MOVWF 4D
0512: CALL 35B
.................... i2c_write(0x02); // REG 0
0513: MOVLW 02
0514: MOVWF 4D
0515: CALL 35B
.................... i2c_write(bin2bcd(ucTemp)); // Start oscillator with current "seconds value
0516: MOVF 4B,W
0517: MOVWF 4C
0518: CALL 3FD
0519: MOVF 78,W
051A: MOVWF 4C
051B: MOVWF 4D
051C: CALL 35B
....................
.................... i2c_start();
051D: MOVLB 01
051E: BSF 0E.1
051F: MOVLW 29
0520: MOVWF 77
0521: DECFSZ 77,F
0522: GOTO 521
0523: BSF 0E.0
0524: MOVLW 28
0525: MOVWF 77
0526: DECFSZ 77,F
0527: GOTO 526
0528: MOVLB 00
0529: BTFSS 0E.0
052A: GOTO 529
052B: MOVLB 02
052C: BCF 0E.1
052D: MOVLB 01
052E: BCF 0E.1
052F: MOVLW 29
0530: MOVWF 77
0531: DECFSZ 77,F
0532: GOTO 531
0533: MOVLB 02
0534: BCF 0E.0
0535: MOVLB 01
0536: BCF 0E.0
.................... i2c_write(0xD0); // WR to RTC
0537: MOVLW D0
0538: MOVLB 00
0539: MOVWF 4D
053A: CALL 35B
.................... i2c_write(0x07); // Control Register
053B: MOVLW 07
053C: MOVWF 4D
053D: CALL 35B
.................... i2c_write(0x10); // Enable squarewave output pin
053E: MOVLW 10
053F: MOVWF 4D
0540: CALL 35B
.................... i2c_stop();
0541: MOVLB 01
0542: BCF 0E.1
0543: NOP
0544: BSF 0E.0
0545: MOVLB 00
0546: BTFSS 0E.0
0547: GOTO 546
0548: MOVLW 29
0549: MOVWF 77
054A: DECFSZ 77,F
054B: GOTO 54A
054C: GOTO 54D
054D: NOP
054E: MOVLB 01
054F: BSF 0E.1
0550: MOVLW 29
0551: MOVWF 77
0552: DECFSZ 77,F
0553: GOTO 552
.................... //restart_wdt();
....................
.................... }
0554: MOVLP 08
0555: MOVLB 00
0556: GOTO 091 (RETURN)
....................
.................... void ds1307_set_date_time(void)
.................... {
.................... ucSec &= 0x7F;
0557: BCF 43.7
.................... ucHour &= 0x3F;
0558: MOVLW 3F
0559: ANDWF 45,F
....................
.................... i2c_start();
055A: MOVLB 01
055B: BSF 0E.1
055C: MOVLW 29
055D: MOVWF 77
055E: DECFSZ 77,F
055F: GOTO 55E
0560: BSF 0E.0
0561: MOVLW 28
0562: MOVWF 77
0563: DECFSZ 77,F
0564: GOTO 563
0565: MOVLB 02
0566: BCF 0E.1
0567: MOVLB 01
0568: BCF 0E.1
0569: MOVLW 29
056A: MOVWF 77
056B: DECFSZ 77,F
056C: GOTO 56B
056D: MOVLB 02
056E: BCF 0E.0
056F: MOVLB 01
0570: BCF 0E.0
.................... i2c_write(0xD0); // I2C write address
0571: MOVLW D0
0572: MOVLB 00
0573: MOVWF 4D
0574: CALL 35B
.................... i2c_write(0x00); // Start at REG 0 - Seconds
0575: CLRF 4D
0576: CALL 35B
.................... i2c_write(bin2bcd(ucSec)); // REG 0
0577: MOVF 43,W
0578: MOVWF 4C
0579: CALL 3FD
057A: MOVF 78,W
057B: MOVWF 4A
057C: MOVWF 4D
057D: CALL 35B
.................... i2c_write(bin2bcd(ucMin)); // REG 1
057E: MOVF 44,W
057F: MOVWF 4C
0580: CALL 3FD
0581: MOVF 78,W
0582: MOVWF 4A
0583: MOVWF 4D
0584: CALL 35B
.................... i2c_write(bin2bcd(ucHour)); // REG 2
0585: MOVF 45,W
0586: MOVWF 4C
0587: CALL 3FD
0588: MOVF 78,W
0589: MOVWF 4A
058A: MOVWF 4D
058B: CALL 35B
.................... i2c_write(bin2bcd(ucDow)); // REG 3
058C: MOVF 49,W
058D: MOVWF 4C
058E: CALL 3FD
058F: MOVF 78,W
0590: MOVWF 4A
0591: MOVWF 4D
0592: CALL 35B
.................... i2c_write(bin2bcd(ucDate)); // REG 4
0593: MOVF 46,W
0594: MOVWF 4C
0595: CALL 3FD
0596: MOVF 78,W
0597: MOVWF 4A
0598: MOVWF 4D
0599: CALL 35B
.................... i2c_write(bin2bcd(ucMonth)); // REG 5
059A: MOVF 47,W
059B: MOVWF 4C
059C: CALL 3FD
059D: MOVF 78,W
059E: MOVWF 4A
059F: MOVWF 4D
05A0: CALL 35B
.................... i2c_write(bin2bcd(ucYear)); // REG 6
05A1: MOVF 48,W
05A2: MOVWF 4C
05A3: CALL 3FD
05A4: MOVF 78,W
05A5: MOVWF 4A
05A6: MOVWF 4D
05A7: CALL 35B
.................... i2c_write(0x00); // REG 7 - Enable squarewave output pin
05A8: CLRF 4D
05A9: CALL 35B
.................... i2c_write('S'); // REG 8 - CheckMark
05AA: MOVLW 53
05AB: MOVWF 4D
05AC: CALL 35B
.................... i2c_write('C'); // REG 9 - CheckMark
05AD: MOVLW 43
05AE: MOVWF 4D
05AF: CALL 35B
.................... i2c_write('V'); // REG A - CheckMark
05B0: MOVLW 56
05B1: MOVWF 4D
05B2: CALL 35B
.................... i2c_stop();
05B3: MOVLB 01
05B4: BCF 0E.1
05B5: NOP
05B6: BSF 0E.0
05B7: MOVLB 00
05B8: BTFSS 0E.0
05B9: GOTO 5B8
05BA: MOVLW 29
05BB: MOVWF 77
05BC: DECFSZ 77,F
05BD: GOTO 5BC
05BE: GOTO 5BF
05BF: NOP
05C0: MOVLB 01
05C1: BSF 0E.1
05C2: MOVLW 29
05C3: MOVWF 77
05C4: DECFSZ 77,F
05C5: GOTO 5C4
.................... //restart_wdt();
.................... }
05C6: MOVLP 08
05C7: MOVLB 00
05C8: GOTO 094 (RETURN)
....................
.................... void ds1307_get_date(void)
.................... {
.................... i2c_start();
.................... i2c_write(0xD0);
.................... i2c_write(0x03); // Start at REG 3 - Day of week
.................... i2c_start();
.................... i2c_write(0xD1);
.................... ucDow = bcd2bin(i2c_read() & 0x7f); // REG 3
.................... ucDate = bcd2bin(i2c_read() & 0x3f); // REG 4
.................... ucMonth = bcd2bin(i2c_read() & 0x1f); // REG 5
.................... ucYear = bcd2bin(i2c_read(0)); // REG 6
.................... i2c_stop();
.................... //restart_wdt();
.................... }
....................
.................... void ds1307_get_time(void)
.................... {
.................... i2c_start();
.................... i2c_write(0xD0);
.................... i2c_write(0x00); // Start at REG 0 - Seconds
.................... i2c_start();
.................... i2c_write(0xD1);
.................... ucSec = bcd2bin(i2c_read() & 0x7f);
.................... ucMin = bcd2bin(i2c_read() & 0x7f);
.................... ucHour = bcd2bin(i2c_read(0) & 0x3f);
....................
.................... i2c_stop();
.................... //restart_wdt();
.................... }
....................
.................... int1 ds1307_get_date_time(void)
.................... {
.................... int8 ucTempT;
.................... //int1 FlagTemp=0;
.................... i2c_start();
*
0644: MOVLB 01
0645: BSF 0E.1
0646: MOVLW 29
0647: MOVWF 77
0648: DECFSZ 77,F
0649: GOTO 648
064A: BSF 0E.0
064B: MOVLW 28
064C: MOVWF 77
064D: DECFSZ 77,F
064E: GOTO 64D
064F: MOVLB 02
0650: BCF 0E.1
0651: MOVLB 01
0652: BCF 0E.1
0653: MOVLW 29
0654: MOVWF 77
0655: DECFSZ 77,F
0656: GOTO 655
0657: MOVLB 02
0658: BCF 0E.0
0659: MOVLB 01
065A: BCF 0E.0
.................... i2c_write(0xD0);
065B: MOVLW D0
065C: MOVLB 00
065D: MOVWF 4D
065E: CALL 35B
.................... i2c_write(0x00); // Start at REG 0 - Seconds
065F: CLRF 4D
0660: CALL 35B
.................... i2c_start();
0661: MOVLB 01
0662: BSF 0E.1
0663: MOVLW 29
0664: MOVWF 77
0665: DECFSZ 77,F
0666: GOTO 665
0667: BSF 0E.0
0668: MOVLW 28
0669: MOVWF 77
066A: DECFSZ 77,F
066B: GOTO 66A
066C: MOVLB 00
066D: BTFSS 0E.0
066E: GOTO 66D
066F: MOVLB 02
0670: BCF 0E.1
0671: MOVLB 01
0672: BCF 0E.1
0673: MOVLW 29
0674: MOVWF 77
0675: DECFSZ 77,F
0676: GOTO 675
0677: MOVLB 02
0678: BCF 0E.0
0679: MOVLB 01
067A: BCF 0E.0
.................... i2c_write(0xD1);
067B: MOVLW D1
067C: MOVLB 00
067D: MOVWF 4D
067E: CALL 35B
.................... ucSec = bcd2bin(i2c_read() & 0x7f);
067F: MOVLW 01
0680: MOVWF 77
0681: CALL 3A5
0682: MOVF 78,W
0683: ANDLW 7F
0684: MOVWF 4B
0685: MOVWF 4D
0686: CALL 3EA
0687: MOVF 78,W
0688: MOVWF 43
.................... ucMin = bcd2bin(i2c_read() & 0x7f);
0689: MOVLW 01
068A: MOVWF 77
068B: CALL 3A5
068C: MOVF 78,W
068D: ANDLW 7F
068E: MOVWF 4B
068F: MOVWF 4D
0690: CALL 3EA
0691: MOVF 78,W
0692: MOVWF 44
.................... ucHour = bcd2bin(i2c_read() & 0x3f);
0693: MOVLW 01
0694: MOVWF 77
0695: CALL 3A5
0696: MOVF 78,W
0697: ANDLW 3F
0698: MOVWF 4B
0699: MOVWF 4D
069A: CALL 3EA
069B: MOVF 78,W
069C: MOVWF 45
.................... ucDow = bcd2bin(i2c_read() & 0x7f); // REG 3
069D: MOVLW 01
069E: MOVWF 77
069F: CALL 3A5
06A0: MOVF 78,W
06A1: ANDLW 7F
06A2: MOVWF 4B
06A3: MOVWF 4D
06A4: CALL 3EA
06A5: MOVF 78,W
06A6: MOVWF 49
.................... ucDate = bcd2bin(i2c_read() & 0x3f); // REG 4
06A7: MOVLW 01
06A8: MOVWF 77
06A9: CALL 3A5
06AA: MOVF 78,W
06AB: ANDLW 3F
06AC: MOVWF 4B
06AD: MOVWF 4D
06AE: CALL 3EA
06AF: MOVF 78,W
06B0: MOVWF 46
.................... ucMonth = bcd2bin(i2c_read() & 0x1f); // REG 5
06B1: MOVLW 01
06B2: MOVWF 77
06B3: CALL 3A5
06B4: MOVF 78,W
06B5: ANDLW 1F
06B6: MOVWF 4B
06B7: MOVWF 4D
06B8: CALL 3EA
06B9: MOVF 78,W
06BA: MOVWF 47
.................... ucYear = bcd2bin(i2c_read()); // REG 6
06BB: MOVLW 01
06BC: MOVWF 77
06BD: CALL 3A5
06BE: MOVF 78,W
06BF: MOVWF 4B
06C0: MOVWF 4D
06C1: CALL 3EA
06C2: MOVF 78,W
06C3: MOVWF 48
.................... ucTempT = i2c_read(); // REG 7
06C4: MOVLW 01
06C5: MOVWF 77
06C6: CALL 3A5
06C7: MOVF 78,W
06C8: MOVWF 4A
.................... ucTempT = i2c_read(); // REG 8
06C9: MOVLW 01
06CA: MOVWF 77
06CB: CALL 3A5
06CC: MOVF 78,W
06CD: MOVWF 4A
.................... if(ucTempT == 'S')
06CE: MOVF 4A,W
06CF: SUBLW 53
06D0: BTFSS 03.2
06D1: GOTO 6FF
.................... {
.................... ucTempT = i2c_read(); // REG 9
06D2: MOVLW 01
06D3: MOVWF 77
06D4: CALL 3A5
06D5: MOVF 78,W
06D6: MOVWF 4A
.................... if(ucTempT == 'C')
06D7: MOVF 4A,W
06D8: SUBLW 43
06D9: BTFSS 03.2
06DA: GOTO 6FF
.................... {
.................... ucTempT = i2c_read(); // REG A
06DB: MOVLW 01
06DC: MOVWF 77
06DD: CALL 3A5
06DE: MOVF 78,W
06DF: MOVWF 4A
.................... if(ucTempT == 'V')
06E0: MOVF 4A,W
06E1: SUBLW 56
06E2: BTFSS 03.2
06E3: GOTO 6FF
.................... {
....................
.................... //FlagTemp = 0;
.................... ucTempT = i2c_read(0);
06E4: CLRF 77
06E5: CALL 3A5
06E6: MOVF 78,W
06E7: MOVWF 4A
.................... i2c_stop();
06E8: MOVLB 01
06E9: BCF 0E.1
06EA: NOP
06EB: BSF 0E.0
06EC: MOVLB 00
06ED: BTFSS 0E.0
06EE: GOTO 6ED
06EF: MOVLW 29
06F0: MOVWF 77
06F1: DECFSZ 77,F
06F2: GOTO 6F1
06F3: GOTO 6F4
06F4: NOP
06F5: MOVLB 01
06F6: BSF 0E.1
06F7: MOVLW 29
06F8: MOVWF 77
06F9: DECFSZ 77,F
06FA: GOTO 6F9
.................... //restart_wdt();
.................... return(0);
06FB: MOVLW 00
06FC: MOVWF 78
06FD: GOTO 718
06FE: MOVLB 00
.................... }
.................... }
.................... }
.................... ucTempT = i2c_read(0);
06FF: CLRF 77
0700: CALL 3A5
0701: MOVF 78,W
0702: MOVWF 4A
.................... i2c_stop();
0703: MOVLB 01
0704: BCF 0E.1
0705: NOP
0706: BSF 0E.0
0707: MOVLB 00
0708: BTFSS 0E.0
0709: GOTO 708
070A: MOVLW 29
070B: MOVWF 77
070C: DECFSZ 77,F
070D: GOTO 70C
070E: GOTO 70F
070F: NOP
0710: MOVLB 01
0711: BSF 0E.1
0712: MOVLW 29
0713: MOVWF 77
0714: DECFSZ 77,F
0715: GOTO 714
.................... //restart_wdt();
.................... return(1);
0716: MOVLW 01
0717: MOVWF 78
.................... }
0718: MOVLP 08
0719: MOVLB 00
071A: GOTO 0DA (RETURN)
.................... //------------------------------------------------ RTC Program End --------------------------------------------------//
....................
....................
....................
.................... //------------------------------------------------ ADC MCP3422 --------------------------------------------------//
.................... void InitADC(void)
.................... {
.................... i2c_start();
....................
.................... //
.................... // MCP3422 ADDRESS BYTE - MSB first
.................... //
.................... // 1 - 1 - 0 - 1 - A2 - A1 - A0 - R/W
.................... //
.................... //
.................... // Part Number - Address Option - Code on package
.................... // MCP3422A0T-E/CH - A0 (000) - CANN
.................... // MCP3422A1T-E/CH - A1 (001) - CBNN
.................... // MCP3422A2T-E/CH - A2 (010) - CCNN
.................... // MCP3422A3T-E/CH - A3 (011) - CDNN
.................... // MCP3422A4T-E/CH - A4 (100) - CENN
.................... // MCP3422A5T-E/CH - A5 (101) - CFNN
.................... // MCP3422A6T-E/CH - A6 (110) - CGNN
.................... // MCP3422A7T-E/CH - A7 (111) - CHNN
.................... //
.................... // Change the address depending on your ADC, check the code on package
.................... // or the invoice from your supplier
.................... //
.................... // 1101XXX0
.................... //
.................... Ack = i2c_write( ADC_ADDR & 0xFE ); // Write mode
....................
.................... //
.................... // MCP3421 CONFIGURATION REGISTER - MSB first
.................... // RDY - C1 - C0 - O/C - S1 - S0 - G1 - G0
.................... //
.................... //Ack = i2c_write( 0b00010000 ); // Continuous conversion - 12bit - PGA = 1V/V
.................... Ack = i2c_write( 0b00011000 ); // Continuous conversion - 16bit - PGA = 1V/V
....................
.................... i2c_stop();
.................... }
....................
.................... //
.................... // Continuous conversion and display on LCD
.................... //
.................... void GetADC(void)
.................... {
.................... int8 i;
.................... i2c_start();
.................... Ack = i2c_write(ADC_ADDR | 0x01); // Send address of MCP3422
.................... for(i=0;i<250;i++);
.................... //
.................... // NOTE: Don't ack the last byte read
.................... //
.................... byte0 = i2c_read( 1 ); // read first byte and send ack
.................... byte1 = i2c_read( 1 ); // read second byte and send ack
.................... // byte2 = i2c_read( 1 ); // read third byte and send ack
.................... conf = i2c_read( 0 ); // read configuration byte - optional
....................
.................... i2c_stop();
....................
.................... //
.................... // Build a int32 from the 3 bytes read
.................... //
.................... // byte0 &= 0b00000001; // Mask unused bits, probably not neccesary
.................... // adc_in = byte0;
.................... // adc_in <<= 8;
.................... // adc_in += byte1;
.................... if(!(conf & 0x80))
.................... {
.................... adc_in = byte0;
.................... adc_in <<= 8;
.................... adc_in = adc_in & 0xFF00;
.................... adc_in += byte1;
.................... adc_in += 3000; //Software Offset
.................... }
.................... }
.................... //------------------------------------------------ ADC MCP3422 End --------------------------------------------------//
....................
.................... void HexData(unsigned int8 ucTempCount)
.................... {
.................... if((ucHexDisp[ucTempCount] >= 'A') && (ucHexDisp[ucTempCount] <= 'Z'))
*
0168: MOVLW 07
0169: ADDWF 50,W
016A: MOVWF 04
016B: MOVLW 20
016C: MOVWF 05
016D: BTFSC 03.0
016E: INCF 05,F
016F: MOVF 00,W
0170: SUBLW 40
0171: BTFSC 03.0
0172: GOTO 1AB
0173: MOVLW 07
0174: ADDWF 50,W
0175: MOVWF 04
0176: MOVLW 20
0177: MOVWF 05
0178: BTFSC 03.0
0179: INCF 05,F
017A: MOVF 00,W
017B: SUBLW 5A
017C: BTFSS 03.0
017D: GOTO 1AB
.................... {
.................... ucOute = (int8)(Alpha_Seg[ucHexDisp[ucTempCount] - 'A']);
017E: MOVLW 07
017F: ADDWF 50,W
0180: MOVWF 04
0181: MOVLW 20
0182: MOVWF 05
0183: BTFSC 03.0
0184: INCF 05,F
0185: MOVLW 41
0186: SUBWF 00,W
0187: MOVWF 77
0188: BCF 03.0
0189: RLF 77,F
018A: MOVF 77,W
018B: MOVWF 51
018C: INCF 77,W
018D: CALL 038
018E: MOVWF 7A
018F: MOVF 51,W
0190: CALL 038
0191: MOVWF 37
.................... ucOutd = (int8)((Alpha_Seg[ucHexDisp[ucTempCount] - 'A']) >> 8);
0192: MOVLW 07
0193: ADDWF 50,W
0194: MOVWF 04
0195: MOVLW 20
0196: MOVWF 05
0197: BTFSC 03.0
0198: INCF 05,F
0199: MOVLW 41
019A: SUBWF 00,W
019B: MOVWF 77
019C: BCF 03.0
019D: RLF 77,F
019E: MOVF 77,W
019F: MOVWF 51
01A0: INCF 77,W
01A1: CALL 038
01A2: MOVWF 7A
01A3: MOVF 51,W
01A4: CALL 038
01A5: MOVWF 51
01A6: MOVF 7A,W
01A7: MOVWF 52
01A8: CLRF 7A
01A9: MOVWF 38
.................... }
.................... else
01AA: GOTO 210
.................... if((ucHexDisp[ucTempCount] >= '0') && (ucHexDisp[ucTempCount] <= '9'))
01AB: MOVLW 07
01AC: ADDWF 50,W
01AD: MOVWF 04
01AE: MOVLW 20
01AF: MOVWF 05
01B0: BTFSC 03.0
01B1: INCF 05,F
01B2: MOVF 00,W
01B3: SUBLW 2F
01B4: BTFSC 03.0
01B5: GOTO 1EE
01B6: MOVLW 07
01B7: ADDWF 50,W
01B8: MOVWF 04
01B9: MOVLW 20
01BA: MOVWF 05
01BB: BTFSC 03.0
01BC: INCF 05,F
01BD: MOVF 00,W
01BE: SUBLW 39
01BF: BTFSS 03.0
01C0: GOTO 1EE
.................... {
.................... ucOute = (int8)(Alpha_Num_Seg[ucHexDisp[ucTempCount] - '0']);
01C1: MOVLW 07
01C2: ADDWF 50,W
01C3: MOVWF 04
01C4: MOVLW 20
01C5: MOVWF 05
01C6: BTFSC 03.0
01C7: INCF 05,F
01C8: MOVLW 30
01C9: SUBWF 00,W
01CA: MOVWF 77
01CB: BCF 03.0
01CC: RLF 77,F
01CD: MOVF 77,W
01CE: MOVWF 51
01CF: INCF 77,W
01D0: CALL 021
01D1: MOVWF 7A
01D2: MOVF 51,W
01D3: CALL 021
01D4: MOVWF 37
.................... ucOutd = (int8)((Alpha_Num_Seg[ucHexDisp[ucTempCount] - '0']) >> 8);
01D5: MOVLW 07
01D6: ADDWF 50,W
01D7: MOVWF 04
01D8: MOVLW 20
01D9: MOVWF 05
01DA: BTFSC 03.0
01DB: INCF 05,F
01DC: MOVLW 30
01DD: SUBWF 00,W
01DE: MOVWF 77
01DF: BCF 03.0
01E0: RLF 77,F
01E1: MOVF 77,W
01E2: MOVWF 51
01E3: INCF 77,W
01E4: CALL 021
01E5: MOVWF 7A
01E6: MOVF 51,W
01E7: CALL 021
01E8: MOVWF 51
01E9: MOVF 7A,W
01EA: MOVWF 52
01EB: CLRF 7A
01EC: MOVWF 38
.................... }
.................... else
01ED: GOTO 210
.................... if(ucHexDisp[ucTempCount] == '-')
01EE: MOVLW 07
01EF: ADDWF 50,W
01F0: MOVWF 04
01F1: MOVLW 20
01F2: MOVWF 05
01F3: BTFSC 03.0
01F4: INCF 05,F
01F5: MOVF 00,W
01F6: SUBLW 2D
01F7: BTFSS 03.2
01F8: GOTO 1FE
.................... {
.................... ucOute = 0xBF;
01F9: MOVLW BF
01FA: MOVWF 37
.................... ucOutd = 0xFB;
01FB: MOVLW FB
01FC: MOVWF 38
.................... }
....................
.................... else
01FD: GOTO 210
.................... {
.................... ucOute = ucHexDisp[ucTempCount];
01FE: MOVLW 07
01FF: ADDWF 50,W
0200: MOVWF 04
0201: MOVLW 20
0202: MOVWF 05
0203: BTFSC 03.0
0204: INCF 05,F
0205: MOVF 00,W
0206: MOVWF 37
.................... ucOutd = ucHexDisp[ucTempCount];
0207: MOVLW 07
0208: ADDWF 50,W
0209: MOVWF 04
020A: MOVLW 20
020B: MOVWF 05
020C: BTFSC 03.0
020D: INCF 05,F
020E: MOVF 00,W
020F: MOVWF 38
.................... }
.................... }
....................
.................... void SevenData(unsigned int8 ucTempCount)
.................... {
.................... if((ucSevenDisp[ucTempCount] >= 'A') && (ucSevenDisp[ucTempCount] <= 'Z'))
*
0097: MOVLW 0F
0098: ADDWF 50,W
0099: MOVWF 04
009A: MOVLW 20
009B: MOVWF 05
009C: BTFSC 03.0
009D: INCF 05,F
009E: MOVF 00,W
009F: SUBLW 40
00A0: BTFSC 03.0
00A1: GOTO 0BA
00A2: MOVLW 0F
00A3: ADDWF 50,W
00A4: MOVWF 04
00A5: MOVLW 20
00A6: MOVWF 05
00A7: BTFSC 03.0
00A8: INCF 05,F
00A9: MOVF 00,W
00AA: SUBLW 5A
00AB: BTFSS 03.0
00AC: GOTO 0BA
.................... {
.................... ucOute = (Seven_Seg[ucSevenDisp[ucTempCount] - 'A']);
00AD: MOVLW 0F
00AE: ADDWF 50,W
00AF: MOVWF 04
00B0: MOVLW 20
00B1: MOVWF 05
00B2: BTFSC 03.0
00B3: INCF 05,F
00B4: MOVLW 41
00B5: SUBWF 00,W
00B6: CALL 07B
00B7: MOVWF 78
00B8: MOVWF 37
.................... }
.................... else
00B9: GOTO 0E8
.................... if((ucSevenDisp[ucTempCount] >= '0') && (ucSevenDisp[ucTempCount] <= '9'))
00BA: MOVLW 0F
00BB: ADDWF 50,W
00BC: MOVWF 04
00BD: MOVLW 20
00BE: MOVWF 05
00BF: BTFSC 03.0
00C0: INCF 05,F
00C1: MOVF 00,W
00C2: SUBLW 2F
00C3: BTFSC 03.0
00C4: GOTO 0DD
00C5: MOVLW 0F
00C6: ADDWF 50,W
00C7: MOVWF 04
00C8: MOVLW 20
00C9: MOVWF 05
00CA: BTFSC 03.0
00CB: INCF 05,F
00CC: MOVF 00,W
00CD: SUBLW 39
00CE: BTFSS 03.0
00CF: GOTO 0DD
.................... {
.................... ucOute = (Seven_Num_Seg[ucSevenDisp[ucTempCount] - '0']);
00D0: MOVLW 0F
00D1: ADDWF 50,W
00D2: MOVWF 04
00D3: MOVLW 20
00D4: MOVWF 05
00D5: BTFSC 03.0
00D6: INCF 05,F
00D7: MOVLW 30
00D8: SUBWF 00,W
00D9: CALL 06F
00DA: MOVWF 78
00DB: MOVWF 37
.................... }
.................... else
00DC: GOTO 0E8
.................... {
.................... ucOute = Seven_Seg[ucSevenDisp[ucTempCount]];
00DD: MOVLW 0F
00DE: ADDWF 50,W
00DF: MOVWF 04
00E0: MOVLW 20
00E1: MOVWF 05
00E2: BTFSC 03.0
00E3: INCF 05,F
00E4: MOVF 00,W
00E5: CALL 07B
00E6: MOVWF 78
00E7: MOVWF 37
.................... }
....................
.................... if((ucSevenDisp[ucTempCount+1] >= 'A') && (ucSevenDisp[ucTempCount+1] <= 'Z'))
00E8: MOVLW 01
00E9: ADDWF 50,W
00EA: ADDLW 0F
00EB: MOVWF 04
00EC: MOVLW 20
00ED: MOVWF 05
00EE: BTFSC 03.0
00EF: INCF 05,F
00F0: MOVF 00,W
00F1: SUBLW 40
00F2: BTFSC 03.0
00F3: GOTO 10E
00F4: MOVLW 01
00F5: ADDWF 50,W
00F6: ADDLW 0F
00F7: MOVWF 04
00F8: MOVLW 20
00F9: MOVWF 05
00FA: BTFSC 03.0
00FB: INCF 05,F
00FC: MOVF 00,W
00FD: SUBLW 5A
00FE: BTFSS 03.0
00FF: GOTO 10E
.................... {
.................... ucOutd = (Seven_Seg[ucSevenDisp[ucTempCount+1] - 'A']);
0100: MOVLW 01
0101: ADDWF 50,W
0102: ADDLW 0F
0103: MOVWF 04
0104: MOVLW 20
0105: MOVWF 05
0106: BTFSC 03.0
0107: INCF 05,F
0108: MOVLW 41
0109: SUBWF 00,W
010A: CALL 07B
010B: MOVWF 78
010C: MOVWF 38
.................... }
.................... else
010D: GOTO 140
.................... if((ucSevenDisp[ucTempCount+1] >= '0') && (ucSevenDisp[ucTempCount+1] <= '9'))
010E: MOVLW 01
010F: ADDWF 50,W
0110: ADDLW 0F
0111: MOVWF 04
0112: MOVLW 20
0113: MOVWF 05
0114: BTFSC 03.0
0115: INCF 05,F
0116: MOVF 00,W
0117: SUBLW 2F
0118: BTFSC 03.0
0119: GOTO 134
011A: MOVLW 01
011B: ADDWF 50,W
011C: ADDLW 0F
011D: MOVWF 04
011E: MOVLW 20
011F: MOVWF 05
0120: BTFSC 03.0
0121: INCF 05,F
0122: MOVF 00,W
0123: SUBLW 39
0124: BTFSS 03.0
0125: GOTO 134
.................... {
.................... ucOutd = (Seven_Num_Seg[ucSevenDisp[ucTempCount+1] - '0']);
0126: MOVLW 01
0127: ADDWF 50,W
0128: ADDLW 0F
0129: MOVWF 04
012A: MOVLW 20
012B: MOVWF 05
012C: BTFSC 03.0
012D: INCF 05,F
012E: MOVLW 30
012F: SUBWF 00,W
0130: CALL 06F
0131: MOVWF 78
0132: MOVWF 38
.................... }
.................... else
0133: GOTO 140
.................... {
.................... ucOutd = Seven_Seg[ucSevenDisp[ucTempCount+1]];
0134: MOVLW 01
0135: ADDWF 50,W
0136: ADDLW 0F
0137: MOVWF 04
0138: MOVLW 20
0139: MOVWF 05
013A: BTFSC 03.0
013B: INCF 05,F
013C: MOVF 00,W
013D: CALL 07B
013E: MOVWF 78
013F: MOVWF 38
.................... }
.................... }
0140: RETURN
....................
.................... #int_timer1
.................... void timer1_isr(void)
.................... {
.................... disable_interrupts(int_timer1);
0141: MOVLB 01
0142: BCF 11.0
.................... clear_interrupt(int_timer1);
0143: MOVF 07,W
0144: MOVLB 00
0145: BCF 11.0
.................... ucCount++;
0146: INCF 34,F
.................... if(ucCount>10)
0147: MOVF 34,W
0148: SUBLW 0A
0149: BTFSC 03.0
014A: GOTO 14C
.................... {
.................... ucCount=0;
014B: CLRF 34
.................... }
....................
.................... if(!FlagSec)
014C: BTFSC 3B.0
014D: GOTO 160
.................... {
.................... uiTimeCounter++;
014E: INCF 35,F
014F: BTFSC 03.2
0150: INCF 36,F
.................... if(uiTimeCounter >1000)
0151: MOVF 36,W
0152: SUBLW 02
0153: BTFSC 03.0
0154: GOTO 160
0155: XORLW FF
0156: BTFSS 03.2
0157: GOTO 15C
0158: MOVF 35,W
0159: SUBLW E8
015A: BTFSC 03.0
015B: GOTO 160
.................... {
.................... FlagSec = 1;
015C: BSF 3B.0
.................... FlagTemp=1;
015D: BSF 3B.1
.................... uiTimeCounter=0;
015E: CLRF 36
015F: CLRF 35
.................... }
.................... }
.................... /* if(!input(KEY1)) uiCountDebounce++;
.................... else
.................... if(!input(KEY2)) uiCountDebounce++;
.................... else
.................... if(!input(KEY3)) uiCountDebounce++;
.................... else
.................... if(!input(KEY4)) uiCountDebounce++;
.................... else uiCountDebounce = 0;
....................
.................... if(uiCountDebounce > 50)
.................... {
.................... uiCountDebounce = 0;
.................... if(!input(KEY1)) ucKey = 1;
.................... else
.................... if(!input(KEY2)) ucKey = 2;
.................... else
.................... if(!input(KEY3)) ucKey = 3;
.................... else
.................... if(!input(KEY4)) ucKey = 4;
.................... }
.................... */
.................... switch(ucCount)
.................... {
0160: MOVF 34,W
0161: ADDLW F5
0162: BTFSC 03.0
0163: GOTO 21D
0164: ADDLW 0B
0165: GOTO 31F
.................... case 0:
.................... case 1:
.................... case 2:
.................... case 3:
.................... case 4:
.................... case 5:
.................... case 6:
.................... case 7:
.................... HexData(ucCount);
0166: MOVF 34,W
0167: MOVWF 50
.................... break;
*
0210: GOTO 21D
.................... case 8:
.................... SevenData(0);
0211: CLRF 50
0212: CALL 097
.................... break;
0213: GOTO 21D
.................... case 9:
.................... SevenData(2);
0214: MOVLW 02
0215: MOVWF 50
0216: CALL 097
.................... break;
0217: GOTO 21D
.................... case 10:
.................... ucOute = ucSevenDisp[4];
0218: MOVF 33,W
0219: MOVWF 37
.................... ucOutd = 0xFF;
021A: MOVLW FF
021B: MOVWF 38
.................... break;
021C: GOTO 21D
.................... }
....................
.................... switch(ucCount)
.................... {
021D: MOVF 34,W
021E: ADDLW F5
021F: BTFSC 03.0
0220: GOTO 315
0221: ADDLW 0B
0222: GOTO 32E
.................... case 0:
.................... output_high(SEL11);
0223: MOVLB 06
0224: BCF 0D.3
0225: MOVLB 07
0226: BSF 0D.3
.................... output_e(ucOute);
0227: MOVLB 01
0228: CLRF 10
0229: MOVLB 00
022A: MOVF 37,W
022B: MOVLB 02
022C: MOVWF 10
.................... output_d(ucOutd);
022D: MOVLB 01
022E: CLRF 0F
022F: MOVLB 00
0230: MOVF 38,W
0231: MOVLB 02
0232: MOVWF 0F
.................... output_low(SEL1) ;
0233: MOVLB 01
0234: BCF 0C.0
0235: MOVLB 02
0236: BCF 0C.0
.................... break;
0237: MOVLB 00
0238: GOTO 315
.................... case 1:
.................... output_high(SEL1) ;
0239: MOVLB 01
023A: BCF 0C.0
023B: MOVLB 02
023C: BSF 0C.0
.................... output_e(ucOute);
023D: MOVLB 01
023E: CLRF 10
023F: MOVLB 00
0240: MOVF 37,W
0241: MOVLB 02
0242: MOVWF 10
.................... output_d(ucOutd);
0243: MOVLB 01
0244: CLRF 0F
0245: MOVLB 00
0246: MOVF 38,W
0247: MOVLB 02
0248: MOVWF 0F
.................... output_low(SEL2) ;
0249: MOVLB 01
024A: BCF 0C.1
024B: MOVLB 02
024C: BCF 0C.1
.................... break;
024D: MOVLB 00
024E: GOTO 315
.................... case 2:
.................... output_high(SEL2) ;
024F: MOVLB 01
0250: BCF 0C.1
0251: MOVLB 02
0252: BSF 0C.1
.................... output_e(ucOute);
0253: MOVLB 01
0254: CLRF 10
0255: MOVLB 00
0256: MOVF 37,W
0257: MOVLB 02
0258: MOVWF 10
.................... output_d(ucOutd);
0259: MOVLB 01
025A: CLRF 0F
025B: MOVLB 00
025C: MOVF 38,W
025D: MOVLB 02
025E: MOVWF 0F
.................... output_low(SEL3) ;
025F: MOVLB 01
0260: BCF 0C.2
0261: MOVLB 02
0262: BCF 0C.2
.................... break;
0263: MOVLB 00
0264: GOTO 315
.................... case 3:
.................... output_high(SEL3) ;
0265: MOVLB 01
0266: BCF 0C.2
0267: MOVLB 02
0268: BSF 0C.2
.................... output_e(ucOute);
0269: MOVLB 01
026A: CLRF 10
026B: MOVLB 00
026C: MOVF 37,W
026D: MOVLB 02
026E: MOVWF 10
.................... output_d(ucOutd);
026F: MOVLB 01
0270: CLRF 0F
0271: MOVLB 00
0272: MOVF 38,W
0273: MOVLB 02
0274: MOVWF 0F
.................... output_low(SEL4) ;
0275: MOVLB 01
0276: BCF 0C.3
0277: MOVLB 02
0278: BCF 0C.3
.................... break;
0279: MOVLB 00
027A: GOTO 315
.................... case 4:
.................... output_high(SEL4) ;
027B: MOVLB 01
027C: BCF 0C.3
027D: MOVLB 02
027E: BSF 0C.3
.................... output_e(ucOute);
027F: MOVLB 01
0280: CLRF 10
0281: MOVLB 00
0282: MOVF 37,W
0283: MOVLB 02
0284: MOVWF 10
.................... output_d(ucOutd);
0285: MOVLB 01
0286: CLRF 0F
0287: MOVLB 00
0288: MOVF 38,W
0289: MOVLB 02
028A: MOVWF 0F
.................... output_low(SEL5) ;
028B: MOVLB 01
028C: BCF 0C.4
028D: MOVLB 02
028E: BCF 0C.4
.................... break;
028F: MOVLB 00
0290: GOTO 315
.................... case 5:
.................... output_high(SEL5) ;
0291: MOVLB 01
0292: BCF 0C.4
0293: MOVLB 02
0294: BSF 0C.4
.... _________________ shambhuvetal |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jan 25, 2012 6:46 am |
|
|
What value are the I2C pullup resistors ?
Have you tried another version of the compiler ? |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
PIC16F1947 |
Posted: Wed Jan 25, 2012 11:33 am |
|
|
Pull up resistor is 10K.
I haven't tried for another version.
i will try it.
Thanks for your valuable advice. _________________ shambhuvetal |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Jan 25, 2012 11:38 am |
|
|
10K seems high to me, I use 3k3 or 4k7 when running 5 volt PICs. |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
PIC16F1947 |
Posted: Wed Jan 25, 2012 11:47 am |
|
|
OK, i will try 4K7.
but pull will not display data from RTC/EEPROM/ADC.
why this will reset CPU?
Confused. _________________ shambhuvetal |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
PIC16F1947 |
Posted: Mon Feb 20, 2012 12:49 pm |
|
|
Problem was when my code jump from page 1 to page 5 it wont works.
It may be because of pointer.
CCS need to solve this problem.
Now I am facing new problems.
1. I can not use two serial ports of PIC16F1947.
I can use only UART1 of this ic.
There no interrupt given by CCS for Serial two.
2. When my code exceed more than 60%, some functions get corrupted.
Suppose function 1 is first having more than 1000bytes code.&
function 2 is next to it having 1000 byte code.
Then function 2 get corrupted. Same function 2 when i cut & paste above function 1 then my function 1 get corrupted.
When I saw call tree in CCS, the function moved to Page 5 not work properly. So please tell me solution for this.
Should I optimize my code to below 50%. Or this bug is fixed in newer version. My compiler Version is 4.114.
Waiting for your reply........... _________________ shambhuvetal |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Feb 20, 2012 3:49 pm |
|
|
Great!
Two people tell you to post a short listing and your response is to post an even longer listing.
With short we mean max. 1 screen page.
After scrolling down down 10 pages I thought it was getting really long, but it continued on, and on, till 48 pages... (just curious, I counted them all).
Sorry, but now I've lost interest in reading the rest of your post.
If you don't want to put effort in making your program smaller, then you haven't learned how to hunt for bugs and I'm not going to waste my time helping you. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Mon Feb 20, 2012 7:29 pm |
|
|
1) the spec sheet says it has 2 hardware UARTS....
2)one solution is to show us SMALL,tiny, ittybitty program that has your problem...as others have pointed out |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Mon Feb 20, 2012 7:57 pm |
|
|
The chip does have two UARTS. They are also in the device database
but the second one is not in the header file. Those entries need to
be added to the header file. Send a message to CCS asking for an
updated file. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
shambhuvetal
Joined: 29 Aug 2008 Posts: 17 Location: Pune
|
Pic16F1947 |
Posted: Tue Feb 21, 2012 1:54 am |
|
|
Dear Sir,
This code is not for debugging purpose.
I am working from last 3 year on CCS cross Compiler.
I have that much experience.
I am just sharing problem so that other guys will take some solution & do not repeat same.
I have solved code error & now only waiting for 2 serial port & above 60% code problem.
Whatever code i uploaded is begining stage of my software.
Now i have optimize & reduces unnecessary routine to avoid this error.
but i can only avoid this, not to solve this.
thats why am doing this.
Thanks again for reading my overviews.
_________________ shambhuvetal |
|
|
|
|
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
|