uncrocks
Newbie level 6
- Joined
- Sep 12, 2012
- Messages
- 14
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,391
I've got a dc-dc power supply to handle the power (9-18v in, 5v out). But how would I go about writing the code for the pic? I know basic java, but I have no idea if that will help.
- - - Updated - - -
I've put together a sort of flow chart for what I need the pic to do:
1 input, 2 Outputs (We'll call them power and control).
Input goes high -> Power pin immediately goes high
Input goes low -> wait 5 min -> If Input is still low, continue -> Control Pin goes high -> wait 2 min -> Power pin goes low.
I'm pretty sure the lack of sleep function has to do with cost (that's the reason it doesn't have a power button).
Thanks for the advice! I'll try these out!
Lbl A
Input B0 as IGN
If IGN=1 {
Output 1 to B1
}
Else {
Goto Lbl A
}
Lbl B
Input B0 as IGN
If IGN=0 {
Delay 300s
Input B0 as IGN
If IGN=0 {
Output 1 to B2
Delay 120s
Output 0 to B1
Output 0 to B2
Goto Lbl A
}
Else {
Goto Lbl B
}
}
Else {
Goto Lbl B
}
I figured I'd start with flow code, and this is what I've come up with so far:
Code:Lbl A Input B0 as IGN If IGN=1 { Output 1 to B1 } Else { Goto Lbl A } Lbl B Input B0 as IGN If IGN=0 { Delay 300s Input B0 as IGN If IGN=0 { Output 1 to B2 Delay 120s Output 0 to B1 Output 0 to B2 Goto Lbl A } Else { Goto Lbl B } } Else { Goto Lbl B }
I'm using a 16F628A
Does that look OK?
Any advice/suggestions?
//************************************************************************************
//**
//** File name: C:\Users\Bryan\Desktop\Raspberry Pi\Pi Control.c
//** Generated by: Flowcode v4.5.20.76
//** Date: Tuesday, December 11, 2012 18:04:51
//** Licence: Free version
//**
//** ***FREE/DEMO VERSION***
//**
//**
//** NOT FOR COMMERCIAL USE
//**
//** http://www.matrixmultimedia.com
//************************************************************************************
#define MX_PIC
//Defines for microcontroller
#define P16F628A
#define MX_EE
#define MX_EE_TYPE3
#define MX_EE_SIZE 128
#define MX_UART
#define MX_UART_B
#define MX_UART_TX 2
#define MX_UART_RX 1
#define MX_PWM
#define MX_PWM_CNT 1
#define MX_PWM_TRIS1 trisb
#define MX_PWM_1 3
//Functions
#define MX_CLK_SPEED 19660800
#ifdef _BOOSTC
#include <system.h>
#endif
#ifdef HI_TECH_C
#include <pic.h>
#endif
//Configuration data
//Internal functions
#include "C:\Program Files (x86)\Matrix Multimedia\Flowcode V4\FCD\internals.h"
//Macro function declarations
void FCM_Power_Off();
//Variable declarations
char FCV_IGN;
//Macro implementations
void FCM_Power_Off()
{
//Delay
//Delay: 300 s
delay_s(255);
delay_s(45);
//Input
//Input: B0 -> IGN
trisb = trisb | 0x01;
FCV_IGN = ((portb & 0x01) == 0x01);
//Decision
//Decision: IGN=0?
if (FCV_IGN==0)
{
//Output
//Output: 1 -> B2
trisb = trisb & 0xfb;
if (1)
portb = (portb & 0xfb) | 0x04;
else
portb = portb & 0xfb;
//Delay
//Delay: 120 s
delay_s(120);
//Output
//Output: 0 -> B1
trisb = trisb & 0xfd;
if (0)
portb = (portb & 0xfd) | 0x02;
else
portb = portb & 0xfd;
//Output
//Output: 0 -> B2
trisb = trisb & 0xfb;
if (0)
portb = (portb & 0xfb) | 0x04;
else
portb = portb & 0xfb;
}
}
void main()
{
//Initialisation
cmcon = 0x07;
//Interrupt initialisation code
option_reg = 0xC0;
//Connection Point
//Connection Point: [A]: A
FCC_Main_A:
;
//Output
//Output: 0 -> B2
trisb = trisb & 0xfb;
if (0)
portb = (portb & 0xfb) | 0x04;
else
portb = portb & 0xfb;
//Input
//Input: B0 -> IGN
trisb = trisb | 0x01;
FCV_IGN = ((portb & 0x01) == 0x01);
//Decision
//Decision: IGN=1?
if (FCV_IGN==1)
{
//Output
//Output: 1 -> B1
trisb = trisb & 0xfd;
if (1)
portb = (portb & 0xfd) | 0x02;
else
portb = portb & 0xfd;
} else {
//Goto Connection Point
//Goto Connection Point: [A]: A
goto FCC_Main_A;
}
//Connection Point
//Connection Point: [B]: B
FCC_Main_B:
;
//Input
//Input: B0 -> IGN
trisb = trisb | 0x01;
FCV_IGN = ((portb & 0x01) == 0x01);
//Decision
//Decision: IGN=0?
if (FCV_IGN==0)
{
//Call Macro
//Call Macro: Power_Off
FCM_Power_Off();
} else {
//Goto Connection Point
//Goto Connection Point: [B]: B
goto FCC_Main_B;
}
//Goto Connection Point
//Goto Connection Point: [A]: A
goto FCC_Main_A;
mainendloop: goto mainendloop;
}
void MX_INTERRUPT_MACRO(void)
{
}
FlowCode looks like the best solution for me, but I just wanted to make sure I'm doing the inputs and outputs right.
;/////////////////////////////////////////////////////////////////////////////////
;// Code Generator: BoostC Compiler - http://www.sourceboost.com
;// Version : 7.03
;// License Type : Lite License (Unregistered)
;// Limitations : PIC12,PIC16 max code size:2048 words, max RAM banks:2, Non commercial use only
;/////////////////////////////////////////////////////////////////////////////////
include "P16F628A.inc"
; Heap block 0, size:95 (0x000000A0 - 0x000000FE)
__HEAP_BLOCK0_BANK EQU 0x00000001
__HEAP_BLOCK0_START_OFFSET EQU 0x00000020
__HEAP_BLOCK0_END_OFFSET EQU 0x0000007E
; Heap block 1, size:43 (0x00000045 - 0x0000006F)
__HEAP_BLOCK1_BANK EQU 0x00000000
__HEAP_BLOCK1_START_OFFSET EQU 0x00000045
__HEAP_BLOCK1_END_OFFSET EQU 0x0000006F
; Heap block 2, size:0 (0x00000000 - 0x00000000)
__HEAP_BLOCK2_BANK EQU 0x00000000
__HEAP_BLOCK2_START_OFFSET EQU 0x00000000
__HEAP_BLOCK2_END_OFFSET EQU 0x00000000
; Heap block 3, size:0 (0x00000000 - 0x00000000)
__HEAP_BLOCK3_BANK EQU 0x00000000
__HEAP_BLOCK3_START_OFFSET EQU 0x00000000
__HEAP_BLOCK3_END_OFFSET EQU 0x00000000
gbl_status EQU 0x00000003 ; bytes:1
gbl_16_LSR EQU 0x00000020 ; bytes:4
gbl_float_detect_tininess EQU 0x00000039 ; bytes:1
gbl_float_rounding_mode EQU 0x0000003A ; bytes:1
gbl_float_exception_flags EQU 0x0000003B ; bytes:1
gbl_17_gbl_aSig EQU 0x00000024 ; bytes:4
gbl_17_gbl_bSig EQU 0x00000028 ; bytes:4
gbl_17_gbl_zSig EQU 0x0000002C ; bytes:4
gbl_17_gbl_aExp EQU 0x0000003C ; bytes:1
gbl_17_gbl_bExp EQU 0x0000003D ; bytes:1
gbl_17_gbl_zExp EQU 0x00000037 ; bytes:2
gbl_17_gbl_aSign EQU 0x0000003E ; bytes:1
gbl_17_gbl_bSign EQU 0x0000003F ; bytes:1
gbl_17_gbl_zSign EQU 0x00000040 ; bytes:1
gbl_17_gbl_zSigZero EQU 0x00000041 ; bytes:1
gbl_17_gbl_ret EQU 0x00000030 ; bytes:4
gbl_indf EQU 0x00000000 ; bytes:1
gbl_tmr0 EQU 0x00000001 ; bytes:1
gbl_pcl EQU 0x00000002 ; bytes:1
gbl_fsr EQU 0x00000004 ; bytes:1
gbl_porta EQU 0x00000005 ; bytes:1
gbl_portb EQU 0x00000006 ; bytes:1
gbl_pclath EQU 0x0000000A ; bytes:1
gbl_intcon EQU 0x0000000B ; bytes:1
gbl_pir1 EQU 0x0000000C ; bytes:1
gbl_tmr1l EQU 0x0000000E ; bytes:1
gbl_tmr1h EQU 0x0000000F ; bytes:1
gbl_t1con EQU 0x00000010 ; bytes:1
gbl_tmr2 EQU 0x00000011 ; bytes:1
gbl_t2con EQU 0x00000012 ; bytes:1
gbl_ccpr1l EQU 0x00000015 ; bytes:1
gbl_ccpr1h EQU 0x00000016 ; bytes:1
gbl_ccp1con EQU 0x00000017 ; bytes:1
gbl_rcsta EQU 0x00000018 ; bytes:1
gbl_txreg EQU 0x00000019 ; bytes:1
gbl_rcreg EQU 0x0000001A ; bytes:1
gbl_cmcon EQU 0x0000001F ; bytes:1
gbl_option_reg EQU 0x00000081 ; bytes:1
gbl_trisa EQU 0x00000085 ; bytes:1
gbl_trisb EQU 0x00000086 ; bytes:1
gbl_pie1 EQU 0x0000008C ; bytes:1
gbl_pcon EQU 0x0000008E ; bytes:1
gbl_pr2 EQU 0x00000092 ; bytes:1
gbl_txsta EQU 0x00000098 ; bytes:1
gbl_spbrg EQU 0x00000099 ; bytes:1
gbl_eedata EQU 0x0000009A ; bytes:1
gbl_eeadr EQU 0x0000009B ; bytes:1
gbl_eecon1 EQU 0x0000009C ; bytes:1
gbl_eecon2 EQU 0x0000009D ; bytes:1
gbl_vrcon EQU 0x0000009F ; bytes:1
gbl_FCV_IGN EQU 0x00000042 ; bytes:1
CompTempVar2201 EQU 0x00000043 ; bytes:1
CompTempVar2203 EQU 0x00000043 ; bytes:1
CompTempVar2204 EQU 0x00000043 ; bytes:1
CompTempVar2206 EQU 0x00000043 ; bytes:1
CompTempVar2207 EQU 0x00000043 ; bytes:1
CompTempVar2208 EQU 0x00000044 ; bytes:1
delay_ms_00000_arg_del EQU 0x00000044 ; bytes:1
delay_s_00000_arg_del EQU 0x00000043 ; bytes:1
Int1Context EQU 0x0000007F ; bytes:1
Int1BContext EQU 0x00000034 ; bytes:3
ORG 0x00000000
GOTO _startup
ORG 0x00000004
MOVWF Int1Context
SWAPF STATUS, W
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF Int1BContext
SWAPF PCLATH, W
MOVWF Int1BContext+D'1'
SWAPF FSR, W
MOVWF Int1BContext+D'2'
BCF PCLATH,3
BCF PCLATH,4
GOTO interrupt
ORG 0x00000010
delay_ms_00000
; { delay_ms ; function begin
MOVF delay_ms_00000_arg_del, F
BTFSS STATUS,Z
GOTO label1
RETURN
label1
MOVLW 0xF5
label2
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
ADDLW 0xFF
BTFSS STATUS,Z
GOTO label2
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DECFSZ delay_ms_00000_arg_del, F
GOTO label1
RETURN
; } delay_ms function end
ORG 0x00000038
delay_s_00000
; { delay_s ; function begin
label3
MOVLW 0xFA
MOVWF delay_ms_00000_arg_del
CALL delay_ms_00000
MOVLW 0xFA
MOVWF delay_ms_00000_arg_del
CALL delay_ms_00000
MOVLW 0xFA
MOVWF delay_ms_00000_arg_del
CALL delay_ms_00000
MOVLW 0xFA
MOVWF delay_ms_00000_arg_del
CALL delay_ms_00000
DECFSZ delay_s_00000_arg_del, F
GOTO label3
RETURN
; } delay_s function end
ORG 0x00000047
FCM_Power__00047
; { FCM_Power_Off ; function begin
MOVLW 0xFF
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF delay_s_00000_arg_del
CALL delay_s_00000
MOVLW 0x2D
MOVWF delay_s_00000_arg_del
CALL delay_s_00000
MOVLW 0x01
BSF STATUS, RP0
IORWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0x01
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF CompTempVar2201
CLRF gbl_FCV_IGN
DECF CompTempVar2201, W
BTFSC STATUS,Z
INCF gbl_FCV_IGN, F
MOVF gbl_FCV_IGN, F
BTFSS STATUS,Z
RETURN
MOVLW 0xFB
BSF STATUS, RP0
ANDWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0xFB
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF CompTempVar2203
MOVLW 0x04
IORWF CompTempVar2203, W
MOVWF gbl_portb
MOVLW 0x78
MOVWF delay_s_00000_arg_del
CALL delay_s_00000
MOVLW 0xFD
BSF STATUS, RP0
ANDWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0xFD
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF gbl_portb
MOVLW 0xFB
BSF STATUS, RP0
ANDWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0xFB
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF gbl_portb
RETURN
; } FCM_Power_Off function end
ORG 0x0000007D
main
; { main ; function begin
MOVLW 0x07
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF gbl_cmcon
MOVLW 0xC0
BSF STATUS, RP0
MOVWF gbl_option_reg
label4
MOVLW 0xFB
BSF STATUS, RP0
ANDWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0xFB
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF gbl_portb
MOVLW 0x01
BSF STATUS, RP0
IORWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0x01
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF CompTempVar2204
CLRF gbl_FCV_IGN
DECF CompTempVar2204, W
BTFSC STATUS,Z
INCF gbl_FCV_IGN, F
DECF gbl_FCV_IGN, W
BTFSS STATUS,Z
GOTO label4
MOVLW 0xFD
BSF STATUS, RP0
ANDWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0xFD
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF CompTempVar2206
MOVLW 0x02
IORWF CompTempVar2206, W
MOVWF gbl_portb
label5
MOVLW 0x01
BSF STATUS, RP0
IORWF gbl_trisb, W
MOVWF gbl_trisb
MOVLW 0x01
BCF STATUS, RP0
ANDWF gbl_portb, W
MOVWF CompTempVar2207
CLRF CompTempVar2208
DECF CompTempVar2207, W
BTFSC STATUS,Z
INCF CompTempVar2208, F
MOVF CompTempVar2208, W
MOVWF gbl_FCV_IGN
MOVF gbl_FCV_IGN, F
BTFSS STATUS,Z
GOTO label5
CALL FCM_Power__00047
GOTO label4
; } main function end
ORG 0x000000B9
_startup
MOVLW 0xD5
BCF STATUS, RP0
BCF STATUS, RP1
MOVWF gbl_16_LSR
MOVLW 0xC4
MOVWF gbl_16_LSR+D'1'
MOVLW 0xBB
MOVWF gbl_16_LSR+D'2'
MOVLW 0xDC
MOVWF gbl_16_LSR+D'3'
CLRF gbl_17_gbl_aSig
CLRF gbl_17_gbl_aSig+D'1'
CLRF gbl_17_gbl_aSig+D'2'
CLRF gbl_17_gbl_aSig+D'3'
CLRF gbl_17_gbl_bSig
CLRF gbl_17_gbl_bSig+D'1'
CLRF gbl_17_gbl_bSig+D'2'
CLRF gbl_17_gbl_bSig+D'3'
CLRF gbl_17_gbl_zSig
CLRF gbl_17_gbl_zSig+D'1'
CLRF gbl_17_gbl_zSig+D'2'
CLRF gbl_17_gbl_zSig+D'3'
CLRF gbl_17_gbl_aExp
CLRF gbl_17_gbl_bExp
CLRF gbl_17_gbl_zExp
CLRF gbl_17_gbl_zExp+D'1'
CLRF gbl_17_gbl_aSign
CLRF gbl_17_gbl_bSign
CLRF gbl_17_gbl_zSign
CLRF gbl_17_gbl_zSigZero
CLRF gbl_17_gbl_ret
CLRF gbl_17_gbl_ret+D'1'
CLRF gbl_17_gbl_ret+D'2'
CLRF gbl_17_gbl_ret+D'3'
CLRF gbl_float_rounding_mode
CLRF gbl_float_exception_flags
CLRF gbl_float_detect_tininess
BCF PCLATH,3
BCF PCLATH,4
GOTO main
ORG 0x000000E1
interrupt
; { interrupt ; function begin
BCF STATUS, RP0
BCF STATUS, RP1
SWAPF Int1BContext+D'2', W
MOVWF FSR
SWAPF Int1BContext+D'1', W
MOVWF PCLATH
SWAPF Int1BContext, W
MOVWF STATUS
SWAPF Int1Context, F
SWAPF Int1Context, W
RETFIE
; } interrupt function end
END
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?