• AVR Freaks

Hot!(SOLVED) Simple project stops working after using.

Author
FermiTin
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2019/05/10 08:05:19
  • Location: 0
  • Status: offline
2019/07/24 09:38:37 (permalink)
0

(SOLVED) Simple project stops working after using.

I have a simple project, that has 6 wires that are able to be discconected (cut). Its like a bomb defusal module. There is also a led, called def_led. It shows that the module does something. After turning on the module, i can pull out the wire (cut it). I am able to pull out the wires from WIRE1 to WIRE6, but after disconnecting 4 wires (in any order) the module stops working (the led stops turning on). What could be the problem? Here is the whole code (made a new project just with the most important parts).
 
Im using PIC18F14K22, XC8 2.0x.
 
main.c
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
 
 
 
// CONFIG1H
#pragma config FOSC = IRC // Oscillator Selection bits->Internal RC oscillator
#pragma config PLLEN = OFF // 4 X PLL Enable bit->PLL is under software control
#pragma config PCLKEN = ON // Primary Clock Enable bit->Primary clock enabled
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable->Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit->Oscillator Switchover mode disabled
 
 
 
// CONFIG2L
#pragma config PWRTEN = OFF // Power-up Timer Enable bit->PWRT disabled
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits->Brown-out Reset enabled in hardware only (SBOREN is disabled)
#pragma config BORV = 19 // Brown Out Reset Voltage bits->VBOR set to 1.9 V nominal
 
 
 
// CONFIG2H
#pragma config WDTEN = OFF // Watchdog Timer Enable bit->WDT is controlled by SWDTEN bit of the WDTCON register
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits->1:32768
 
 
 
// CONFIG3H
#pragma config HFOFST = ON // HFINTOSC Fast Start-up bit->HFINTOSC starts clocking the CPU without waiting for the oscillator to stablize.
#pragma config MCLRE = ON // MCLR Pin Enable bit->MCLR pin enabled, RA3 input pin disabled
 
 
 
// CONFIG4L
#pragma config STVREN = ON // Stack Full/Underflow Reset Enable bit->Stack full/underflow will cause Reset
#pragma config LVP = ON // Single-Supply ICSP Enable bit->Single-Supply ICSP enabled
#pragma config BBSIZ = OFF // Boot Block Size Select bit->1kW boot block size
#pragma config XINST = OFF // Extended Instruction Set Enable bit->Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
#pragma config DEBUG = OFF // Background Debugger Enable bit->Background debugger disabled, RA0 and RA1 configured as general purpose I/O pins
 
 
 
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit->Block 0 not code-protected
#pragma config CP1 = OFF // Code Protection bit->Block 1 not code-protected
 
 
 
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit->Boot block not code-protected
#pragma config CPD = OFF // Data EEPROM Code Protection bit->Data EEPROM not code-protected
 
 
 
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit->Block 0 not write-protected
#pragma config WRT1 = OFF // Write Protection bit->Block 1 not write-protected
 
 
 
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit->Configuration registers not write-protected
#pragma config WRTB = OFF // Boot Block Write Protection bit->Boot block not write-protected
#pragma config WRTD = OFF // Data EEPROM Write Protection bit->Data EEPROM not write-protected
 
 
 
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit->Block 0 not protected from table reads executed in other blocks
#pragma config EBTR1 = OFF // Table Read Protection bit->Block 1 not protected from table reads executed in other blocks
 
 
 
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit->Boot block not protected from table reads executed in other blocks
 
 
 

int main(int argc, char** argv) {
/**
LATx registers
*/
LATA = 0x00;
LATB = 0x00;
LATC = 0x00;
 
 
 
/**
TRISx registers
*/
TRISA = 0x37;
TRISB = 0xF0;
TRISC = 0xFF;
 
 
 
/**
ANSELx registers
*/
ANSEL = 0x00;
ANSELH = 0x00;
 
 
 
/**
WPUx registers
*/
WPUB = 0x00;
WPUA = 0x00;
 
 
 
//Set to input the 6 wires
WIRE1_TRIS = 1;
WIRE2_TRIS = 1;
WIRE3_TRIS = 1;
WIRE4_TRIS = 1;
WIRE5_TRIS = 1;
WIRE6_TRIS = 1;

//Set the defused led to output
DEF_LED_TRIS = 0;
//Set the defused led to off
DEF_LED = 0;

while(1){
if(WIRE1 == 0 || WIRE2 == 0 || WIRE3 == 0 || WIRE4 == 0 || WIRE5 == 0 || WIRE6 == 0){
DEF_LED = 1;
}else{
DEF_LED = 0;
}
}
}
 
 
 

 
main.h
#ifndef MAIN_H
#define MAIN_H
 
 
 
#include <xc.h>
 
 
 
#define _XTAL_FREQ 1000000
 
 
 
#define INPUT 1
#define OUTPUT 0
 
 
 
#define HIGH 1
#define LOW 0
 
 
 
#define ANALOG 1
#define DIGITAL 0
 
 
 
#define PULL_UP_ENABLED 1
#define PULL_UP_DISABLED 0
 
 
 
//Definition of input of wires that can be cut/pulled out
#define WIRE1 PORTAbits.RA5
#define WIRE2 PORTCbits.RC5
#define WIRE3 PORTCbits.RC4
#define WIRE4 PORTCbits.RC3
#define WIRE5 PORTCbits.RC6
#define WIRE6 PORTCbits.RC7
 
 
 
//Definition of wires (TRIS) that can be cut/pulled out
#define WIRE1_TRIS TRISAbits.TRISA5
#define WIRE2_TRIS TRISCbits.TRISC5
#define WIRE3_TRIS TRISCbits.TRISC4
#define WIRE4_TRIS TRISCbits.TRISC3
#define WIRE5_TRIS TRISCbits.TRISC6
#define WIRE6_TRIS TRISCbits.TRISC7
 
 
 
//Definition of output of led, which turns on, when module is solved
#define DEF_LED LATCbits.LATC2
 
 
 
//Definition of register of led, which turns on, when module is solved
#define DEF_LED_TRIS TRISCbits.TRISC2
 
 
 
#endif /* MAIN_H */
 
 
 

 
 
post edited by FermiTin - 2019/08/14 10:20:40

Attached Image(s)

#1

2 Replies Related Threads

    FermiTin
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2019/05/10 08:05:19
    • Location: 0
    • Status: offline
    Re: Simple project stops working after using. 2019/08/14 10:20:08 (permalink)
    +1 (1)
    SOLVED!
     
    I was discconecting "cutting" the wire that was connected to a PGM pin. I set LVP to off, and that made the PGM pin behave like a normal I/O and that solved the problem.
    #2
    pcbbc
    Super Member
    • Total Posts : 1245
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: online
    Re: Simple project stops working after using. 2019/08/14 11:55:11 (permalink)
    +1 (1)
    What’s with this definition of main...
    int main(int argc, char** argv)

    What arguments are you expecting to receive into an embedded application?
    What are you expecting to receive the returned value, and where are you expecting an embedded application to return to?

    The correct syntax for CC8 is...
    void main(void)
    #3
    Jump to:
    © 2019 APG vNext Commercial Version 4.5