CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I have problem to use Interrupt RB pin4-7c in PIC16LF876

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
HGHK



Joined: 29 Jun 2010
Posts: 33

View user's profile Send private message Yahoo Messenger

I have problem to use Interrupt RB pin4-7c in PIC16LF876
PostPosted: Sat Dec 25, 2010 3:32 am     Reply with quote

I need use PORT B Change Interrupt (pins RB7:RB4), moreover External Interrupt (pin B0) in a PIC16LF876 to active my device from sleep.
This interrupt doesn't work carefully and when I make a pulse in pin B5 no action where down. Please help me ASAP!
My program is :TERMOCUNTERPIC16LF876.c:
Code:
 
#include "C:\Documents and Settings\HGhK\Desktop\CRP\temp project\TERMOCUNTERPIC16LF876.h"

#int_RB
void  RB_isr(void)
{
PKC++;
if((Command!=Press_Key_First)||(Command!=Press_Key_Second)||(Command!=Press_Key_Third)){Pervius_Command=Command;}
switch (PKC){
case  1: Command=Press_Key_First;PK1=1;PK2=0;PK3=0;break;
case  2: command=Press_Key_Second;PK1=0;PK2=1;PK3=0;break;
default: command=Press_Key_Third;PK1=0;PK2=0;PK3=1;PKC=0;break;
            }
OFC=0;
set_timer0(0);
enable_interrupts(INT_TIMER0);}

#int_EXT
void  EXT_isr(void)
{
ExINT=1;
Pervius_Command=Command;
Command=Routine_Temperature_Sampling;
}

#int_TIMER0
void  TIMER0_isr(void)
{
OFC++;
if (OFC==0xFFFE){OFC=0x0000;}
clear_interrupt(INT_TIMER0);}

#int_RDA
void  RDA_isr(void)
{
RC=0;RXin=0;
RXin=getch();
if (CC){
Pervius_Command=Command;
Command=RXin;}
else if (RXin==Are_You_ready){Pervius_Command=Command;Command=Controller_Connected;CC=1;}
OFC=0;
set_timer0(0);
}

void main()
{

output_high(LED1);
output_high(LED2);

if (!Cal_A) {Cal_A = 165;}
if (!Cal_B) {Cal_B = 328;}
if (!Cal_C) {Cal_C =  20;}
if (!Cal_D) {Cal_D = -40;}
if (!Temp_Down_Limit) {Temp_Down_Limit=Temperature_Low_Limit_Defult;}
if (!Temp_Up_Limit) {Temp_Up_Limit=Temperature_Up_Limit_Defult;}
if (!Sleep_Priod_Division_Reg) {Sleep_Priod_Division_Reg=Time_Period_Defult_Division;}

   setup_adc_ports(AN0);set_adc_channel(0);
   setup_adc(ADC_CLOCK_INTERNAL);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_ccp2(CCP_OFF);
   enable_interrupts(INT_RB);
   disable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);ext_int_edge(H_TO_L);
   port_b_pullups(1);

disable_interrupts(GLOBAL);
PCF8563_init();
while(1){
enable_interrupts(GLOBAL);
   switch (Command) {

    case 0x11:       // Routine Temperature Sampling
          disable_interrupts(GLOBAL);
          Err=0;
          PCF8563_Clear_Alarm_Flag();
          Temperature_Exam = Temperature();
          if ((Temperature_Exam>Temp_Down_Limit)&&(Temp_Up_Limit>Temperature_Exam)) {TSC = TSC+1;}
          PCF8563_Read_SMH();
          ALARM_MINS_REG = MINUTES_REG + 60/Sleep_Priod_Division_Reg;
          if (ALARM_MINS_REG > 59) {ALARM_MINS_REG -= 60 ;};
          PCF8563_Set_Alarm();
        Reset_Command();
          clear_interrupt(INT_EXT);ExINT=0;
          enable_interrupts(GLOBAL);
           break;

    case 0x12:       // Report Temperature Sampling counter
          disable_interrupts(INT_RDA);
          clear_interrupt(INT_RDA);
          Err=0;
          Temperature_Exam = Temperature();
          ReportTSC(Temperature_Exam);   
          Reset_Command();
          enable_interrupts(INT_RDA);
           break;

    case 0x14:       // Reset Temperature Sampling counter Set Sleep Priode
              putc(I_am_ready);
              disable_interrupts(INT_RDA);
              If (kbhit()) {RXin=getch();
                            if (RXin<60) {Sleep_Priod_Division_Reg=RXin;TSC=0;}
                            Reset_Command();
                            enable_interrupts(INT_RDA);
                           }
              break;

    case 0x18:       // Report Temprature Limits

           Reset_Command();
           break;
 
    case 0x21:       // Set Temperature Limits

           Reset_Command();
           break;

    case 0x22:       // Report Temprature       

           Reset_Command();
           break;

    case 0x24:       // Press_Key_First
          Err=0;
          if (OFC>2){clear_interrupt(INT_RB);}
          Temperature_Exam = Temperature();
          putLCD(Temperature_Exam,1);
          if (OFC>120){Reset_Command();putLCD(0,0);}
           break;

    case 0x28:       // Press_Key_Second
          Err=0;
          if (OFC>2){clear_interrupt(INT_RB);}
          Calculation=TSC*Sleep_Priod_Division_Reg/60;
          putLCD(Calculation,1);
          if (OFC>120){Reset_Command();putLCD(0,0);}
           break;

    case 0x41:       // Press_Key_Third
              Err=0;
              if (OFC>2){clear_interrupt(INT_RB);}             
              putLCD(0,0);
              PKC=0;PK1=0;
              PK2=0;PK3=0;
              disable_interrupts(INT_TIMER0);
              Reset_Command();
           break;

    case 0x42:       // Batry_Voltage_Sampling
              Err=0; 
              disable_interrupts(INT_RB);
              enable_interrupts(INT_TIMER0);
              if (!BVS ){OFC=0;BVS=1;}
              if (OFC>8){Reset_Command();enable_interrupts(INT_RB);disable_interrupts(INT_TIMER0);}
           break;

    case 0x44:       // Calibration_Setting 

           Reset_Command();
           break;

    case 0x48:       // Report_Time_And_Date 

           Reset_Command();
           break;

    case 0x81:       // Set_Time_And_Date

           Reset_Command();
           break;

    case 0x82:       // Controller_Connected
            Err=0; 
            if ((CC)&&(!(input_state(ES)))){Command=0x82;}
            if ((CC)&&(input_state(ES))&&(BVS )){Command=0x42;}
            enable_interrupts(INT_TIMER0);
            disable_interrupts(INT_RDA);
            clear_interrupt(INT_RDA);
            if (OFC>8) { putc(Are_You_ready);
                         OFC=0;
                         delay_ms(10);
                         If (kbhit()) {RXin=getch();if (RXin == I_am_ready){CC=1;}else{CC=0;Reset_Command();}}
                       }
            break;

    case 0x84:       // Ricived_From_Controller

           Reset_Command();
           break;

    case 0x88:       // Controller_Disconnected
         
           Err=0;
           CC=0;
           Reset_Command();
           break;

                    }
If (Command == None_Command){
 
            if ((Pervius_Command)&&(!Err)) {Command=Pervius_Command;Err=1;}
            else  {
                   PCF8563_Read_SMH();
                   if ( MINUTES_REG > ALARM_MINS_REG ){
                      if (!(((ALARM_MINS_REG+60)> MINUTES_REG)&&(MINUTES_REG > (ALARM_MINS_REG + 60 - (60/Sleep_Priod_Division_Reg)))))
                      {
                      ALARM_MINS_REG = MINUTES_REG  +  ( 60 / Sleep_Priod_Division_Reg);
                      if (ALARM_MINS_REG > 59) {ALARM_MINS_REG-=60;}
                      PCF8563_Set_Alarm();
                      PCF8563_Clear_Alarm_Flag();
                      }                                }
                      Reset_Command();
                      clear_interrupt(INT_EXT);
                      clear_interrupt(INT_RB);
                      clear_interrupt(INT_RTCC);
                      clear_interrupt(INT_RDA);
                      clear_interrupt(GLOBAL);
                      enable_interrupts(INT_RB);
                      enable_interrupts(INT_EXT);
                      enable_interrupts(INT_RDA);
                      enable_interrupts(GLOBAL);
                      if (!Command) {sleep();}
                   }

                            }
 }}


And its header is :TERMOCUNTERPIC16LF876.h :

Code:

#include <16F876.h>
#device ICD=TRUE
#device adc=10

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected
#FUSES DEBUG                    //Debug mode for use with ICD

#use delay(clock=2000000)
#define SDN    PIN_A1
#define DIG1   PIN_A2
#define DATA3  PIN_A3
#define LED1   PIN_A4
#define LED2   PIN_A5
#define EINT   PIN_B0
#define DIG3   PIN_B1
#define DIG4   PIN_B2
#define DE     PIN_B3
#define ES     PIN_B5
#define PGC    PIN_B6
#define PGD    PIN_B7
#define DATA2  PIN_C0
#define DATA1  PIN_C1
#define DATA0  PIN_C2
#define DIG2   PIN_C5
#define TX     PIN_C6
#define RX     PIN_C7
#use rs232(baud=4464,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw)


#define Time_Period_Defult_Division           2
#define Temperature_Up_Limit_Defult           5
#define Temperature_Low_Limit_Defult          0

// command set definition

#define None_Command                 0x00
#define Routine_Temperature_Sampling 0x11
#define Report_TSC                   0x12    // TSC : Temprature Sampling Counter
#define Reset_TSC_Set_Sleep_Priode   0x14
#define Report_Temprature_Limits     0x18
#define Set_Temperature_Limits       0x21
#define Report_Temprature            0x22
#define Press_Key_First              0x24
#define Press_Key_Second             0x28
#define Press_Key_Third              0x41
#define Batry_Voltage_Sampling       0x42
#define Calibration_Setting          0x44
#define Report_Time_And_Date         0x48
#define Set_Time_And_Date            0x81
#define Controller_Connected         0x82
#define Ricived_From_Controller      0x83
#define Controller_Disconnected      0x88

void DataEE_Read(int32 addr, int8 * ram, int bytes) {
     int i;
     for(i=0;i<=bytes;i++,ram++,addr++)
     *ram=read_eeprom(addr);
     }
void DataEE_Write(int32 addr, int8 * ram, int bytes) {
     int i;
     for(i=0;i<=bytes;i++,ram++,addr++)
     write_eeprom(addr,*ram);
     }
addressmod (eepromdata,DataEE_read,DataEE_write,0x00,0xff);          // would define a region called DataEE between 0x5 and 0xff in the chip data EEprom.

signed   int8  eepromdata Temp_Up_Limit,Temp_Down_Limit;
signed   int16 eepromdata Cal_A,Cal_B,Cal_C,Cal_D;
unsigned int8  eepromdata Sleep_Priod_Division_Reg;
unsigned int8  eepromdata EEPROM_Pervius_Command,EEPROM_Command;
unsigned int32 eepromdata TSC;
unsigned int32            Calculation; 
unsigned int16            A2DC;
unsigned int8             Pervius_Command=None_Command,Command=None_Command,Condition;
unsigned int8             OFC;           // 15sec counter
unsigned int8             PKC,RC;        //press key counter , Rambler cOunter
unsigned int8             RXin,TXout; 
signed   int8             Temperature_Exam,Up,Down;
   

/*

    ************** CONDITION VARIABLE ***************
    +-----+-----+-----+-----+-----+-----+-----+-----+
    |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
    +-----+-----+-----+-----+-----+-----+-----+-----+ 
    | Err | BVS | RXA |ExINT| PK3 | PK2 | PK1 | CC  |     
    +-----+-----+-----+-----+-----+-----+-----+-----+

*/

#bit Err  = Condition.7
#bit BVS  = Condition.6   // Batry Voltage sampling Condition
#bit RXA  = Condition.5
#bit ExINT= Condition.4
#bit PK3  = Condition.3
#bit PK2  = Condition.2
#bit PK1  = Condition.1
#bit CC   = Condition.0   // Controller Connected


typedef struct
{
int8 seconds;    // 0 to 59
int8 minutes;    // 0 to 59
int8 hours;      // 0 to 23  (24-hour time)
int8 day;        // 1 to 31
int8 weekday;    // 0 = Sunday, 1 = Monday, etc.
int8 month;      // 1 to 12
int8 year;       // 00 to 99
}date_time_t;

typedef struct
{
int8 minutes;    // 0 to 59
int8 hours;      // 0 to 23  (24-hour time)
int8 day;        // 1 to 31
int8 weekday;    // 0 = Sunday, 1 = Monday, etc.
}PCF8563_Alarm;


// -------------------------------------------------

#define Are_You_ready   0x3c
#define I_am_ready      0xc3

// -------------------------------------------------

#ifndef PCF8563_SDA
#define PCF8563_SDA  PIN_C4
#define PCF8563_SCL  PIN_C3
#endif

// #use i2c(master, sda=PCF8563_SDA, scl=PCF8563_SCL)


#ifndef PCF8563_WRITE_ADDRESS
#define PCF8563_WRITE_ADDRESS 0xA2
#define PCF8563_READ_ADDRESS  0xA3
#endif

// Register addresses
#define PCF8563_CTRL_STATUS_REG1   0x00
#define PCF8563_CTRL_STATUS_REG2   0x01
#define PCF8563_SECONDS_REG        0x02
#define PCF8563_MINUTES_REG        0x03
#define PCF8563_HOURS_REG          0x04
#define PCF8563_DAY_REG            0x05
#define PCF8563_WEEK_REG           0x06
#define PCF8563_MONTH_REG          0x07
#define PCF8563_YEAR_REG           0x08
#define PCF8563_ALARM_MINS_REG     0x09
#define PCF8563_ALARM_HOURS_REG    0x0A
#define PCF8563_ALARM_DAY_REG      0x0B
#define PCF8563_ALARM_WEEKDAY_REG  0x0C
#define PCF8563_CTRL_CLKOUT_REG    0x0D
#define PCF8563_CTRL_TIMER_REG     0x0E
#define PCF8563_TIMER_REG          0x0F


int8 CTRL_STATUS_REG1,CTRL_STATUS_REG2,LV_sec,MINUTES_REG;
int8 HOURS_REG,DAY_REG,WEEK_REG,C_Mon,YEAR_REG;
int8 CTRL_TIMER_REG,TIMER_REG,CTRL_CLKOUT_REG;
int8 ALARM_MINS_REG,ALARM_HOURS_REG;


#bit LowVoltage = LV_sec.7
#bit Century = C_Mon.7

   
#define  bcd_min   MINUTES_REG
#define  bcd_hrs   HOURS_REG
#define  bcd_day   DAY_REG
#define  bcd_yer   YEAR_REG
#define  wek       WEEK_REG

// Commands for the Control/Status register.
#define PCF8563_START_COUNTING     0x08
#define PCF8563_STOP_COUNTING      0x28


//*************************************  for Set_Alarm()
#define PCF8563_Alarm_off          0x00
#define PCF8563_M_Mode             0x01
#define PCF8563_MH_Mode            0x04
#define PCF8563_MHW_Mode           0x07
#define PCF8563_MHD_Mode           0x0B 

//*************************************  for config_CLKOUT()
#define PCF8563_CLKOUT_off         0x00
#define PCF8563_CLKOUT_32KHz       0x80
#define PCF8563_CLKOUT_1KHz        0x81
#define PCF8563_CLKOUT_32Hz        0x82
#define PCF8563_CLKOUT_1Hz         0x83

//*************************************  for config_PCF8563_Timer()
#define PCF8563_Timer_off          0x00
#define PCF8563_Timer_4KHz         0x80
#define PCF8563_Timer_64Hz         0x81
#define PCF8563_Timer_1Hz          0x82
#define PCF8563_Timer_1_60Hz       0x83

//*************************************  for config_PCF8563_Interrupt()
#define Alarm_Interrupt_Enable     0x01
#define Timer_Interrupt_Enable     0x02
#define A_T_Interrupt_Enable       0x03
#define Timer_INT_Pulse_on         0x10
#define Timer_INT_Pulse_off        0x00


int8 bin2bcd(int8 value)
{
char retval = 0;


while(1)
  {
   // Get the tens digit by doing multiple subtraction
   // of 10 from the binary value.
   if(value >= 10)
     {
      value -= 10;
      retval += 0x10;
     }
   else // Get the ones digit by adding the remainder.
     {
      retval += value;
      break;
     }
   }

return(retval);
}

//----------------------------------------------
// This function converts an 8 bit BCD value to
// an 8 bit binary value.
// The input range must be from 00 to 99.

char bcd2bin(char bcd_value)
{
char temp;

temp = bcd_value;

// Shifting the upper digit right by 1 is
// the same as multiplying it by 8.
temp >>= 1;

// Isolate the bits for the upper digit.
temp &= 0x78;

// Now return: (Tens * 8) + (Tens * 2) + Ones
return(temp + (temp >> 2) + (bcd_value & 0x0f));

}


//----------------------------------------------
void PCF8563_write_byte(int8 address, int8 data)
{
disable_interrupts(GLOBAL);
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(address);
i2c_write(data);
i2c_stop();
enable_interrupts(GLOBAL);
}   

//----------------------------------------------
int8 PCF8563_read_byte(int8 address)
{
int8 retval;
disable_interrupts(GLOBAL);
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(address);
i2c_start();
i2c_write(PCF8563_READ_ADDRESS);
retval = i2c_read(0);
i2c_stop();
enable_interrupts(GLOBAL);
return(retval);
}   

//----------------------------------------------
//           PCF8563 Initial              // //

void PCF8563_init(void)
{
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(PCF8563_CTRL_STATUS_REG1);
i2c_write(PCF8563_START_COUNTING);
i2c_write(0x02);   // CTRL_STATUS_REG2
i2c_write(1);      // SECONDS_REG
i2c_write(1);      // MINUTES_REG
i2c_write(1);      // HOURS_REG
i2c_write(1);      // DAY_REG
i2c_write(1);      // WEEK_REG
i2c_write(1);      // MONTH_REG
i2c_write(1);      // YEAR_REG
i2c_stop();
}
void PCF8563_Read_SMH(void)
{
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(PCF8563_SECONDS_REG);
i2c_start();
i2c_write(PCF8563_READ_ADDRESS);
LV_sec         =i2c_read();
MINUTES_REG    =i2c_read();
HOURS_REG      =i2c_read();
                i2c_read();
                i2c_read();
                i2c_read();
                i2c_read();
ALARM_MINS_REG =i2c_read();
ALARM_HOURS_REG=i2c_read(0);
i2c_stop();
}
void PCF8563_Clear_Alarm_Flag(void)
{
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(PCF8563_CTRL_STATUS_REG2);
i2c_write(0x02);
i2c_stop();
}
void PCF8563_Set_Alarm(void)
{
i2c_start();
i2c_write(PCF8563_WRITE_ADDRESS);
i2c_write(PCF8563_ALARM_MINS_REG);
i2c_write(ALARM_MINS_REG);
i2c_write(0x80);   // ALARM_HOURS_REG
i2c_write(0x80);   // ALARM_DAY_REG
i2c_write(0x80);   // MINUTES_REG
i2c_write(0x80);   // ALARM_WEEKDAY_REG
i2c_write(0x80);   // CTRL_CLKOUT_REG
i2c_write(0x00);   // CTRL_TIMER_REG
i2c_stop();
}

//----------------------------------------------

void config_PCF8563_Interrupt(int8 mode,ti_tp)
{
mode = mode | ti_tp;
PCF8563_write_byte(PCF8563_CTRL_STATUS_REG2, mode);
}

/***************************************************************************
**************************** ICM7211AIPL ***********************************
****************************************************************************/

int8 dig[4];

typedef struct {
   signed int quot;
   signed int rem;
} div_t;
//**************************************************
div_t div(signed int numer, signed int denom)
{
   div_t val;
   val.quot = numer / denom;
   val.rem = numer - (denom * val.quot);
   return (val);
}
//***************************************************
void show_Digit(int8 intercode)
     {
     intercode = intercode & 0x0F;
       switch (intercode)
              {
               case 0:output_low(DATA3);output_low(DATA2);output_low(DATA1);output_low(DATA0);break;       //FOR 0
               case 1:output_low(DATA3);output_low(DATA2);output_low(DATA1);output_high(DATA0);break;      //FOR 1
               case 2:output_low(DATA3);output_low(DATA2);output_high(DATA1);output_low(DATA0);break;      //FOR 2
               case 3:output_low(DATA3);output_low(DATA2);output_high(DATA1);output_high(DATA0);break;     //FOR 3
               case 4:output_low(DATA3);output_high(DATA2);output_low(DATA1);output_low(DATA0);break;      //FOR 4
               case 5:output_low(DATA3);output_high(DATA2);output_low(DATA1);output_high(DATA0);break;     //FOR 5
               case 6:output_low(DATA3);output_high(DATA2);output_high(DATA1);output_low(DATA0);break;     //FOR 6
               case 7:output_low(DATA3);output_high(DATA2);output_high(DATA1);output_high(DATA0);break;    //FOR 7
               case 8:output_high(DATA3);output_low(DATA2);output_low(DATA1);output_low(DATA0);break;      //FOR 8
               case 9:output_high(DATA3);output_low(DATA2);output_low(DATA1);output_high(DATA0);break;     //FOR 9
               case 10:output_high(DATA3);output_low(DATA2);output_high(DATA1);output_low(DATA0);break;    //FOR -
               case 11:output_high(DATA3);output_low(DATA2);output_high(DATA1);output_high(DATA0);break;   //FOR E
               default:output_high(DATA3);output_high(DATA2);output_high(DATA2);output_high(DATA0);break;  //FOR BLANK
              }
      }
//  *******************************************************
void putLCD(signed int16 value,int8 lcd_power_switch )
     {
if (lcd_power_switch)
                       {
     div_t numb; 
     int8 mode=0x00,i;
  if (value > 9999 || value < 999 ){
                                    for (i=0;i>=3;++i) dig[1]=11;
                                   }
else                              {
     
     for (i=0;i>=3;++i) dig[1]=12;
     if (value<0) {
                   value=value*(-1);
                   mode = 0x10;
                   dig[3] = 10;
                   }
     if (value>999){
                    numb=div(value,1000);
                          dig[3] = numb.quot;
                          value = numb.rem;
                          mode  +=  0x08 ;
                   }

     if (value>99){
                    numb=div(value,100);
                         dig[2] = numb.quot;
                         value = numb.rem;
                         mode +=  0x04 ;
                   }

     if (value>9){ 
                    numb=div(value,10);
                    dig[1] = numb.quot;
                    value = numb.rem;
                    mode +=  0x02 ;
                   }

     if (value > -1){
                     dig[0] = value; 
                     mode += 0x01;
                    }
                       }
output_high(DE);   delay_us(2);                     
output_high(DIG1); delay_us(2);
show_Digit(dig[0]);delay_us(2);
output_low(DIG1); 
output_high(DIG2); delay_us(2);
show_Digit(dig[1]);delay_us(2);
output_low(DIG2); 
output_high(DIG3); delay_us(2);
show_Digit(dig[2]);delay_us(2);
output_low(DIG3); 
output_high(DIG4); delay_us(2);
show_Digit(dig[3]);delay_us(2);
output_low(DIG4);  delay_us(2);
show_Digit(0);
if (lcd_power_switch==1) {output_high(LED2);output_high(LED2);output_low(LED1);}
if (lcd_power_switch==2) {output_high(LED1);output_high(LED1);output_low(LED2);}
                       }
else {
output_high(DE);   delay_us(2);                     
output_high(DIG1); delay_us(2);
show_Digit(dig[0]);delay_us(2);
output_low(DIG1); 
output_high(DIG2); delay_us(2);
show_Digit(dig[1]);delay_us(2);
output_low(DIG2); 
output_high(DIG3); delay_us(2);
show_Digit(dig[2]);delay_us(2);
output_low(DIG3); 
output_high(DIG4); delay_us(2);
show_Digit(dig[3]);delay_us(2);
output_low(DIG4); 
show_Digit(0);
output_low(DE);
output_high(LED1);
output_high(LED2);
output_high(LED2);
output_high(LED1);
     }               
      }

// +*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+
// /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

signed int8 Temperature(void){

          output_high(SDN);
          delay_us(80);
          setup_adc_ports(AN0);set_adc_channel(0);
          setup_adc(ADC_CLOCK_INTERNAL);
          A2DC=read_adc();
          delay_us(10);
          output_low(SDN);
 Return make8((((Cal_A * ( A2DC - Cal_C))/Cal_B) + Cal_D),0);
                              }
//---------------------------------------------------
void ReportTSC(int32 inp){

int8 i,dig[4],temp;

dig[0]= make8(inp,0);
dig[1]= make8(inp,1);
dig[2]= make8(inp,2);
dig[3]= make8(inp,3);
temp=Sleep_Priod_Division_Reg;
putc(I_am_ready);
for(i=0;i=3;i++)putc(dig[i]);
putc(temp);
                          }
//---------------------------------------------------

void Reset_Command(void){

if (Pervius_Command){Command=Pervius_Command;Pervius_Command=0x00;
   enable_interrupts(INT_RB);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT);
   enable_interrupts(GLOBAL);}
else
    {
     if (PK1){Command=0x24;enable_interrupts(INT_RB);}
     if (PK2){Command=0x28;enable_interrupts(INT_RB);}
     if (PK3){Command=0x41;enable_interrupts(INT_RB);}
     if (CC){Command=0x82;}
     if (ExINT){Command=0x11;}
     enable_interrupts(INT_RDA);
     enable_interrupts(INT_EXT);
     enable_interrupts(GLOBAL);
     }                  }
//---------------------------------------------------


Thanks, if you help me and explain me about using PORT B Change Interrupt (pins RB7:RB4) in other simplest code and guide me about using it so it worked carefully.
_________________
My Gmail is:
HGholizadehK@Gmail.com
You can send pm for me in it


Last edited by HGHK on Tue Jan 04, 2011 3:09 am; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Dec 25, 2010 2:51 pm     Reply with quote

PortB must be read inside the #int_RB routine, to clear the "Mismatch
condition". This is stated in the PIC data sheet. To do this, add the
code (shown in bold below) to your program.
Quote:

// This function reads Port B without changing the TRIS.

int8 input_state_b(void)
{
#byte PortB = getenv("SFR:PORTB")

return(PortB);
}


#int_RB
void RB_isr(void)
{
int8 temp;

PKC++;
if((Command!=Press_Key_First)||(Command!=Press_Key_Second)||(Command!=Press_Key_Third)){Pervius_Command=Command;}
switch (PKC){
case 1: Command=Press_Key_First;PK1=1;PK2=0;PK3=0;break;
case 2: command=Press_Key_Second;PK1=0;PK2=1;PK3=0;break;
default: command=Press_Key_Third;PK1=0;PK2=0;PK3=1;PKC=0;break;
}
OFC=0;
set_timer0(0);
enable_interrupts(INT_TIMER0);

temp = input_state_b(); // Clear mismatch condition on Port B
}


Quote:

#include <16F876.h>
#device ICD=TRUE
#device adc=10

#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#FUSES DEBUG //Debug mode for use with ICD

#use delay(clock=2000000)

Do you really have a 2 MHz crystal ? That's very unusual. Or is it
really supposed to be 20 MHz ? If so, edit the #use delay() statement
and also change the fuse from XT to HS.

Are you using the INT output pin of the pcf8563 ? If so, you need a
pull-up resistor on it. You can use 4.7K ohms.
HGHK



Joined: 29 Jun 2010
Posts: 33

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Dec 28, 2010 7:08 am     Reply with quote

Dear PCM programmer
thanks
I test it, but noises make interrupt in another pin from B4-B7. I must pull-up Port B but I made my PCB and I don't know why when I use
Code:
port_b_pullups(1);

in my program the port doesn't pull up.
I used 1MHz crystal before but I don't find it in shops and I prefer 2MHz crystal for low consuming power requirements in PIC16LF876 series and I2C baud rate true setting. Also it find in shops!
If you have a better offer I very like to know.
I use PCF8563 Interrupt for wake up from sleep and I pull up it by 4.7K resistor. So I pull up Pin B5 and it connect with Push-pull bottom and noise reduction capacitor to GND.

Thanks for your help. Wink
_________________
My Gmail is:
HGholizadehK@Gmail.com
You can send pm for me in it
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 28, 2010 12:51 pm     Reply with quote

Quote:
I must pull-up Port B but I made my PCB and I don't know why when I use:
port_b_pullups(1);
in my program the port doesn't pull up.

Then make a small test program and study how to use the
port_b_pullups() function.


I looked in your program for the port_b_pullups() line, which you say
you have in there. I didn't find it. But I did see this problem:
Quote:

void ReportTSC(int32 inp){

int8 i,dig[4],temp;

dig[0]= make8(inp,0);
dig[1]= make8(inp,1);
dig[2]= make8(inp,2);
dig[3]= make8(inp,3);
temp=Sleep_Priod_Division_Reg;
putc(I_am_ready);
for(i=0;i=3;i++)putc(dig[i]); putc(temp);
}

What does that line do ? How can "i=3" work ?
Here is a test program to test that line of code:
Code:
#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//==========================================
void main()
{
int8 i;

for(i=0;i=3;i++) putc('A');

while(1);
}


Here is the output:
Quote:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

Your code does not work correctly.

You need to study "for loops" in the C language and learn how to make
a correct for() statement.
HGHK



Joined: 29 Jun 2010
Posts: 33

View user's profile Send private message Yahoo Messenger

PostPosted: Tue Jan 04, 2011 4:19 am     Reply with quote

Quote:
I looked in your program for the port_b_pullups() line, which you say
you have in there. I didn't find it.

I placed corrections that you offered in my program. Thanks for your attention. but in ccs c manual says that:
Quote:
for
For is also used as a loop/iteration statement.
The syntax is
for (expr1;expr2;expr3)
statement
The expressions are loop control statements. expr1 is the initialization, expr2 is the termination check and expr3 is re-initialization. Any of them can be omitted.
Example:
for (i=1;i<=10;++i)
printf("%u\r\n",i);

I think termination check means that when I come to expr2 this loop is end of screwing and when this loop were end next line go runs.
pleas help me that what of these:
Code:
for(i=0;i<=3;i++)putc(dig[i]);

or
Code:
for(i=0;i>3;i++)putc(dig[i]);

is ok?
_________________
My Gmail is:
HGholizadehK@Gmail.com
You can send pm for me in it
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 04, 2011 1:22 pm     Reply with quote

Make a test program. Test it with each of those lines of code.
Then you can see what each line does.

You can test it with the MPLAB simulator:

See this post for instructions on how to use the "UART1" feature of the
MPLAB simulator to display serial output in the MPLAB Output Window:
http://www.ccsinfo.com/forum/viewtopic.php?t=23408&start=1
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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