• AVR Freaks

Hot!16f88 output

Page: 12 > Showing page 1 of 2
Author
rogerpic
Starting Member
  • Total Posts : 71
  • Reward points : 0
  • Joined: 2018/01/06 04:06:07
  • Location: 0
  • Status: offline
2019/04/24 08:11:27 (permalink)
0

16f88 output

*
 * File:   car2.c
 * Author: 
 *
 * Created on 20 april 2019, 9:39
 */
 
#include "htc.h"
#include "xc.h"
#include "stdio.h"
#include "pic16f88.h"
#pragma delay;
#pragma MCLRE_OFF;
#pragma CP_OFF;
#pragma MCPU_OFF;
#pragma IOSCFS_4MHZ;
#define OSCCONbits.IRCF = 0b111;        // Set internal oscillator frequency to 8MHz
#define OSCCONbits.SCS  = 0b10;         // Internal RC is used for system clock
// BEGIN CONFIG
#pragma config FOSC = HS // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF // Flash Program Memory Code Protection bit (Code protection off)
//END CONFIG
 
#define ANSELA3 = 1;
#define TRISA3 = 1;
#define ANSELA0 = 0;
#define TRISA0 = 0;

int main(){
   
   
    PORTAbits.RA0 = 1;                             
 /* Nothing happens on breadboard? Weird situation. It programs but no reaction the output RA0 stays 0;     
/* What is want i want is a input condition and the another output goes up.

      
    
   }
   
   The output don't go up
#1

21 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1228
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: 16f88 output 2019/04/24 08:18:02 (permalink)
    +1 (1)
    You must not allow your code to exist the main loop. It probably resetting. 
    Put your PORTAbits.RA0 = 1;   inside a while(1) loop  

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    jack@kksound
    code tags!
    • Total Posts : 3183
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 09:08:14 (permalink)
    +1 (1)
    There are so many things wrong with your code, a few here:
    #define ANSELA3 = 1;
    #define TRISA3 = 1;
    #define ANSELA0 = 0;
    #define TRISA0 = 0;

    using a #define here does NOT set the registers, you must actually do that in your code. The ports default to input mode so unless you set the TRISAbits.RAO bit to a zero (0) you will still be in input mode and get no output "reaction".
     
    #3
    NKurzman
    A Guy on the Net
    • Total Posts : 17248
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 09:26:59 (permalink)
    0
    Can we assume you are using the XC8 Compiler?
    #4
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 09:46:36 (permalink)
    0
    Yes XC8 compiler yes that's true
    #5
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 09:52:19 (permalink)
    0
    what weird is when a input goes high another follows and that i have doesn't program that following pin.
    #6
    pcbbc
    Super Member
    • Total Posts : 926
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 10:01:59 (permalink)
    +1 (1)
    #pragma config WDTE = ON // Watchdog Timer Enable bit (WDT enabled)

    Turn watchdog OFF unless you plan on using it correctly.
     
    Your code as posted is borked.  It will do all kinds of weird stuff due to the mistakes you have made.
    Post updated code with the fixes made as suggested.
     
    Edit: Oh, and please put [CODE]code tags[/CODE] around your code.  The words "code" should be in lower case to get your code to format correctly.
    post edited by pcbbc - 2019/04/24 10:03:04
    #7
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 10:36:59 (permalink)
    0
    a relais that's connected and that works the input goes up or low when the relais is on or off.
    But other pins go also high and low if that specific input where the relais is connected.
    I didn't program other pins
    #8
    jack@kksound
    code tags!
    • Total Posts : 3183
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 10:49:24 (permalink)
    +2 (2)
    rogerpic
    a relais that's connected and that works the input goes up or low when the relais is on or off.
    But other pins go also high and low if that specific input where the relais is connected.
    I didn't program other pins


    Lookup RMW effects on this forum.
    #9
    pcbbc
    Super Member
    • Total Posts : 926
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 11:34:09 (permalink)
    +2 (2)
    Because you have enabled the watchdog timer in config, you chip will be randomly resetting when the watchdog times out.
    Because you haven't coded a while (1) { }; loop in main, your main function will return to "nowhere" (this isn't Arduino Sketching), and again cause all kinds of random effects and resets.
     
    Any defined behaviour is out of the window when you make such mistakes.  Fix them and try again.  If you make changes, re-post your code or we have no idea what you are trying.
     
    relais?  Do you perhaps mean RELAY?
    #10
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 11:41:27 (permalink)
    0
    Yes on a relay is the switch connected to a pin. And via a solarpanel the relais attracts on. but it seems with no code at all pins go also high when the switch is on or off. There is no code just empty main with void and a while. Its a begin of writing the code. some header files i loaded thats all.
    #11
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 11:46:12 (permalink)
    0
    Yes RELAY
    #12
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 12:09:19 (permalink)
    0
    Nothing i program just een open braces with accolades and 2 header files to begin to write but it goes wrong if light falls on the solar panel and then attracts a relay but if the output goes high then other following. My hardware is a resistor connected to supply and that resistor other end lead to the switch output from the relay. I use the same supply like my controller. Supply controller is the same as from the resistor. Is there maybe a fault. for simplicity that switch is or open or close and then is or "1" or '0'. The resistor is used  with the switch. And the relay contacts with solar and also that supply
    #13
    rogerpic
    Starting Member
    • Total Posts : 71
    • Reward points : 0
    • Joined: 2018/01/06 04:06:07
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 12:09:19 (permalink)
    0
    Nothing i program just een open braces with accolades and 2 header files to begin to write but it goes wrong if light falls on the solar panel and then attracts a relay but if the output goes high then other following. My hardware is a resistor connected to supply and that resistor other end lead to the switch output from the relay. I use the same supply like my controller. Supply controller is the same as from the resistor. Is there maybe a fault. for simplicity that switch is or open or close and then is or "1" or '0'. The resistor is used  with the switch. And the relay contacts with solar and also that supply
    #14
    rodims
    Super Member
    • Total Posts : 1478
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: 16f88 output 2019/04/24 12:15:11 (permalink)
    +1 (1)
    It seems as if you do not listen to any of the advice given to you,  but simply ignore them.
    Your original code doesn't do anything meaningful.
     
    As pcbbc already wrote:
    Any defined behaviour is out of the window when you make such mistakes.  Fix them and try again. 
    If you make changes, re-post your code or we have no idea what you are trying !
     
    #15
    qhb
    Superb Member
    • Total Posts : 9990
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: 16f88 output 2019/04/24 13:09:38 (permalink)
    +1 (1)
    Do as everyone else has advised, but also, change
    #include "htc.h"
    #include "xc.h"
    #include "stdio.h"
    #include "pic16f88.h"

    to just:
    #include "xc.h"

    you don't need all the other files there.

    Only 10 to go...
    #16
    jack@kksound
    code tags!
    • Total Posts : 3183
    • Reward points : 0
    • Joined: 2014/05/14 10:03:19
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/24 13:21:33 (permalink)
    +1 (1)
    Sounds from your description that you may be having severe power source issues in addition to the code problems.
    #17
    katela
    Super Member
    • Total Posts : 1228
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: 16f88 output 2019/04/24 14:48:17 (permalink)
    +2 (2)
    rogerpic
    a relais that's connected and that works the input goes up or low when the relais is on or off.
    But other pins go also high and low if that specific input where the relais is connected.
    I didn't program other pins


    Post your revised code as advised above and post also your schematic to see how your relay is connected.
    The more info you provide, the easier to get support.
    And start by fixing first what you have been advised to do.




    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #18
    pcbbc
    Super Member
    • Total Posts : 926
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: 16f88 output 2019/04/25 00:14:51 (permalink)
    +2 (2)
    rogerpicIs there maybe a fault.
    Yes, there’s a fault.
    That’s all I got from that, sorry.
    #19
    mlp
    boots too small
    • Total Posts : 738
    • Reward points : 0
    • Joined: 2012/09/10 15:12:07
    • Location: previously Microchip XC8 team
    • Status: offline
    Re: 16f88 output 2019/04/25 06:41:43 (permalink)
    +1 (1)
    qhb
    Do as everyone else has advised, but also, change
    #include "htc.h"
    #include "xc.h"
    #include "stdio.h"
    #include "pic16f88.h"

    to just:
    #include "xc.h"

    you don't need all the other files there.

    Better:
    #include <xc.h>
    This will ensure that the compiler's copy of xc.h is used.

    Mark (this opinion available for hire)
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5