/Designs/dum/SW/simple/main.PJT
0,0 → 1,41
[PROJECT]
Target=main.HEX
Development_Mode=2
Processor=0x4550
Processor_Text=PIC18F4550
ToolSuite=CCS
 
[Directories]
Include=
Library=
LinkerScript=
 
[Target Data]
FileList=C:\Dokumenty\PIC\dum\main.c
BuildTool=C-COMPILER
OptionString=+FH
AdditionalOptionString=
BuildRequired=1
 
[main.c]
Type=4
Path=
FileList=
BuildTool=
OptionString=
AdditionalOptionString=
 
[mru-list]
1=main.c
 
[Windows]
0=0000 main.c 0 0 796 451 3 0
 
[Opened Files]
1=main.c
2=main.h
3=..\..\..\Program Files\PICC\devices\18F4550.h
4=
[Units]
Count=1
1=main (main)
/Designs/dum/SW/simple/main.c
0,0 → 1,186
/* DUM - provizorni ovladani svetel a rolet na hvezdarne */
#include "main.h"
 
#CASE // Case sensitive compiler
 
#define ZAKMIT 100 // Cas pro osetreni zakmitu v ms
#define ZATAHNUTI 30000 // Cas potrebny na vysunuti rolety v ms
#define REVERZ 300 // Cas pro reverzaci v ms
 
#define S1_2 PIN_D0 // T1 Svetlo
#define S1_5 PIN_D1 // T2
#define S2_7 PIN_D2 // T3
#define R2_7U PIN_D3 // T4 Roleta
#define R2_7D PIN_D4 // T5
#define S2_9 PIN_D5 // T6
#define S2_3 PIN_D6 // T7
#define S2_1 PIN_D7 // T8
 
#define V1_2 !input(PIN_A0) // A Vypinac
#define V2_1 !input(PIN_A1) // B
#define V2_7 !input(PIN_A2) // C
#define V2_7U !input(PIN_A3) // D Vypinac puleny
#define V2_7D !input(PIN_A4) // E
#define V2_6 !input(PIN_A5) // F
#define V2_9 !input(PIN_E0) // G
#define V2_3 !input(PIN_E1) // H
 
#define ON(port) output_low(port);
#define OFF(port) output_high(port);
 
typedef enum {UP, DOWN, NOTHING} request;
 
void main()
{
int t1_2, t1_5; // Casovace
int16 t2_7r;
int16 t2_7;
int vs1_2, vs1_2_old, vs1_5, vs1_5_old; // Vypinac schodistovy
#bit vs1_2_0 = vs1_2.0
#bit vs1_2_1 = vs1_2.1
#bit vs1_2_2 = vs1_2.2
int v2_7, v2_7_old;
#bit v2_7d = v2_7.0
#bit v2_7u = v2_7.1
#bit v2_7d_old = v2_7_old.0
#bit v2_7u_old = v2_7_old.1
request pozadavek2_7;
 
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_ccp1(CCP_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
 
printf("ahoj\r\n");
 
output_d(0xFF); // Vsechno zhasnout
vs1_5 = V1_2; // Inicializace schodistaku
vs1_5_old = vs1_5;
vs1_2 = 0;
vs1_2_1 = V2_1;
vs1_2_2 = V2_6;
vs1_2_old = vs1_2;
v2_7 = 0; // Inicializace rolety
v2_7d = V2_7D;
v2_7u = V2_7U;
v2_7_old = v2_7;
t2_7 = ZATAHNUTI / 2;
while(TRUE)
{
vs1_2_1 = V2_1; // Precti stavy schodistaku a vypinacu rolet
vs1_2_2 = V2_6;
vs1_5 = V1_2;
v2_7d = V2_7D;
v2_7u = V2_7U;
// Schodiste a kuchyn ----------------------------------------------------------
if ((vs1_5 != vs1_5_old) && (0 == t1_5))
{
vs1_5_old = vs1_5;
t1_5 = ZAKMIT;
if (!input_state(S1_5) && input_state(S1_2))
{
OFF(S1_5)
} else
if (input_state(S1_5) && input_state(S1_2))
{
ON(S1_5)
ON(S1_2)
ON(S2_1)
} else
if (!input_state(S1_5) && !input_state(S1_2))
{
OFF(S1_5)
} else
if (input_state(S1_5) && !input_state(S1_2))
{
OFF(S1_2)
OFF(S2_1)
}
}
if ((vs1_2_old != vs1_2) && (0 == t1_2)) // Schodiste
{
vs1_2_old = vs1_2;
t1_2 = ZAKMIT;
output_toggle(S1_2);
output_toggle(S2_1);
}
// Roleta klubovna -------------------------------------------------------------
if ((v2_7u_old != v2_7u) && (t2_7 > 0) && (0 == t2_7r)) // Pokud je pozadavek nahoru a nejsme nahore
{
if (!input_state(R2_7U)) // Nejedeme zrovna nahoru?
{
pozadavek2_7 = NOTHING; // Poznamenej pozadavek
printf("pozadavek NOTHING\r\n");
}
else
{
pozadavek2_7 = UP; // Poznamenej pozadavek
printf("pozadavek UP\r\n");
}
OFF(R2_7D) // Zastav
OFF(R2_7U) // Zastav
t2_7r = REVERZ; // Cas pro zmenu pohybu
v2_7_old = v2_7; // Poznamenej zmenu vypinace
}
 
if ((v2_7d_old != v2_7d) && (t2_7 < ZATAHNUTI) && (0 == t2_7r)) // Pokud je pozadavek dolu a nejsme dole
{
if (!input_state(R2_7D)) // Nejedeme zrovna dolu?
{
pozadavek2_7 = NOTHING; // Poznamenej pozadavek
printf("pozadavek NOTHING\r\n");
}
else
{
pozadavek2_7 = DOWN; // Poznamenej pozadavek
printf("pozadavek DOWN\r\n");
}
OFF(R2_7D) // Zastav
OFF(R2_7U) // Zastav
t2_7r = REVERZ; // Cas pro zmenu pohybu
v2_7_old = v2_7; // Poznamenej zmenu vypinace
}
if ((UP == pozadavek2_7) && (0 == t2_7r))
{
printf("UP\r\n");
ON(R2_7U)
pozadavek2_7 = NOTHING;
}
if ((DOWN == pozadavek2_7) && (0 == t2_7r))
{
printf("DOWN\r\n");
ON(R2_7D)
pozadavek2_7 = NOTHING;
}
if (t2_7 == 0) OFF(R2_7U);
if (t2_7 == ZATAHNUTI) OFF(R2_7D);
// Obycejna svetla ------------------------------------------------------------
if (V2_7) ON(S2_7) else OFF(S2_7)
if (V2_3) ON(S2_3) else OFF(S2_3)
if (V2_9) ON(S2_9) else OFF(S2_9)
delay_ms(1);
 
if (t1_2>0) t1_2--;
if (t1_5>0) t1_5--;
if (t2_7r>0) t2_7r--;
if ((t2_7>0) && (!input_state(R2_7U))) t2_7--;
if ((t2_7<ZATAHNUTI) && (!input_state(R2_7D))) t2_7++;
}
}
/Designs/dum/SW/simple/main.h
0,0 → 1,38
#include <18F4550.h>
//#device ICD=TRUE
//#device adc=10
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES HSPLL //High Speed Crystal/Resonator with PLL enabled
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV46 //Brownout reset at 4.6V
#FUSES NOPUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //Debug mode for use with ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOIESO //Internal External Switch Over mode disabled
#FUSES NOFCMEN //Fail-safe clock monitor disabled
#FUSES NOPBADEN //PORTB pins are configured as digital I/O on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES NOLPT1OSC //Timer1 configured for low-power operation
//#FUSES XINST //Extended set extension and Indexed Addressing mode
#FUSES PLL5 //Divide By 5 (20MHz oscillator input) = 4MHz
#FUSES CPUDIV1 //System Clock 96/2 = 48MHz
#FUSES NOUSBDIV //USB clock source comes from primary oscillator
#FUSES NOVREGEN //USB voltage regulator disabled
#FUSES NOICPRT //ICPRT disabled
 
#use delay(clock=48000000,RESTART_WDT)
#use rs232(baud=9600,parity=N,bits=8,xmit=PIN_B7,rcv=PIN_B6)