• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help to correct the source code...

Status
Not open for further replies.
I just make a 16F72 based 6 Chanel switch with toggle and Tactile controle...

But Its not work in the hardware...

Please take a look in to the source code.

Any help would be appriciated..

Code:
sbit SW0 at RA0_bit;
sbit SW1 at RA1_bit;
sbit SW2 at RA2_bit;
sbit SW3 at RA3_bit;
sbit SW4 at RA4_bit;
sbit SW5 at RA5_bit;

sbit SW6 at RC0_bit;

sbit LED0 at RB0_bit;
sbit LED1 at RB0_bit;
sbit LED2 at RB0_bit;
sbit LED3 at RB0_bit;
sbit LED4 at RB0_bit;
sbit LED5 at RB0_bit;

#define TACTILE_MODE 0
#define TOGGLE_MODE  1

unsigned char myFlags = 0;

sbit mode at myFlags.B0;

void main() {

  asm clrwdt

  OPTION_REG = 0x8F;
   
  TRISA = 0x3F;
  TRISB = 0x00;
  TRISC = 0x01;
   
  PORTA = 0x00;
  PORTB = 0x00;
  PORTC = 0x00;
   
  Delay_ms(200);
   
  while(1) {
   
  asm clrwdt
   
  if(SW6 == 0) {
  Delay_ms(50);
  if(SW6 == 0) {
  mode = TACTILE_MODE;
  }
  }
  else if(SW6 == 1) {
  Delay_ms(50);
  if(SW6 == 1) {
  mode = TOGGLE_MODE;
  }
  }
   
  if(TACTILE_MODE) {
  if(RA0_bit) {
  Delay_ms(50);
  if(RA0_bit) {
  LED0 = 1;
  }
  }
  else if(!RA0_bit) {
  Delay_ms(50);
  if(!RA0_bit) {
  LED0 = 0;
  }
  }
   
  if(RA1_bit) {
  Delay_ms(50);
  if(RA1_bit) {
  LED1 = 1;
  }
  }
  else if(!RA1_bit) {
  Delay_ms(50);
  if(!RA1_bit) {
  LED1 = 0;
  }
  }
   
  if(RA2_bit) {
  Delay_ms(50);
  if(RA2_bit) {
  LED2 = 1;
  }
  }
  else if(!RA2_bit) {
  Delay_ms(50);
  if(!RA2_bit) {
  LED2 = 0;
  }
  }
   
  if(RA3_bit) {
  Delay_ms(50);
  if(RA3_bit) {
  LED3 = 1;
  }
  }
  else if(!RA3_bit) {
  Delay_ms(50);
  if(!RA3_bit) {
  LED3 = 0;
  }
  }
   
  if(RA4_bit) {
  Delay_ms(50);
  if(RA4_bit) {
  LED4 = 1;
  }
  }
  else if(!RA4_bit) {
  Delay_ms(50);
  if(!RA4_bit) {
  LED4 = 0;
  }
  }
   
  if(RA5_bit) {
  Delay_ms(50);
  if(RA5_bit) {
  LED5 = 1;
  }
  }
  else if(!RA5_bit) {
  Delay_ms(50);
  if(!RA5_bit) {
  LED5 = 0;
  }
  }
  }
  else if(TOGGLE_MODE) {
   
  if(RA0_bit) {
  Delay_ms(50);
  while(RA0_bit)asm clrwdt;
  LED0 = ~LED0;
  }
   
  if(RA1_bit) {
  Delay_ms(50);
  while(RA1_bit)asm clrwdt;
  LED1 = ~LED1;
  }
   
  if(RA2_bit) {
  Delay_ms(50);
  while(RA2_bit)asm clrwdt;
  LED2 = ~LED2;
  }
   
  if(RA3_bit) {
  Delay_ms(50);
  while(RA3_bit)asm clrwdt;
  LED3 = ~LED3;
  }
   
  if(RA4_bit) {
  Delay_ms(50);
  while(RA4_bit)asm clrwdt;
  LED4 = ~LED4;
  }
   
  if(RA5_bit) {
  Delay_ms(50);
  while(RA5_bit)asm clrwdt;
  LED5 = ~LED5;
  }
  }
  }
}

[code]
 

sagor1

Active Member
Why all sbit LED0 to LED5 all RB0? Should they not be RB0 to RB1,2,3,4 and 5??
The way LED0-5 is defined, and LEDx will toggle or turn on RB0 only
 

sagor1

Active Member
It states the error is in Config 0000-something. Re-check your chip configuration flags. Something may be set wrong.
 
Its my first programme...

I am learning...

In this source, Only the RA5 and RB5 are only working in toggle mode.. Not waorking other switches and also tactile mode...


This is my proteus file with 16F916. There are no 16F72 in proteus ...
 

Attachments

sagor1

Active Member
Cannot read proteus file, it is not text, nor Oshonsoft basic code.
You can disable the WDT with the config bits, then remove all that code related to WDT. Not sure why you would want that anyway for a simple toggle program.

It may be that RA5 and RB5 are working because they are at the end of the loops, and are the last bit of code executed. It may be a code flow problem (no jumps or exits, just keeps going to next statement)
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top