I'm new here and hope it is ok that my first post is a Question . I'm new in programming and hope you can teach me.
To the function
Adjustable on and off time adjustable pressure and loop yes / no
An adjustable vacuum in the vacuum accumulator, which is measured by a pressure sensor (comparator), is to be generated during the period of the off time . When the off time is over, the vacuum should be released into the system via a shuttle valve. After this time, the pressure in the system is to be drained via a venting valve. The whole is shown on the display.
Nothing displayed and I do not know why.
My question is it possible or am I completely on the wrong way.
Thanks
Stefan
Code: Select all
/* Vacuum Station
By modena
*/
// LCD modul
sbit LCD_RS at RA1_bit;
sbit LCD_EN at RA5_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISA1_bit;
sbit LCD_EN_Direction at TRISA5_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
// Hysterese
sbit MENU_sw at RA2_bit;
sbit SELECT_sw at RA3_bit;
sbit ENTER_sw at RA4_bit;
sbit START_sw at RB0_bit;
sbit Pumpen_Relais at RB3_bit;
sbit Wechsel_Ventil at RB2_bit;
sbit Entluef_Ventil at RB1_bit;
sbit Sensor at RA0_bit;
sbit Sensor_Direction at TRISA0_bit;
// Nachrichten definition
char NA2[] = " Pause = ";
char NA3[] = " Vacuum = ";
char NA4[] = " Druck =-";
char NA5[] = " Y/N = ";
unsigned short SS_Pos = 10;
unsigned short Mbar_Pos = 10;
unsigned short AN_Zeit[] = {0, 0};
unsigned short Aus_Zeit[] = {0, 0,};
unsigned short Mbar [] = {0, 0};
unsigned short Modus_AUSWAHL = 0 ;
unsigned short Repeat_Cycle=0, Num_Cycles=0;
unsigned short i, j, k, Timer_An, Get_Input, Cur_Pos, Cur_On;
unsigned short temp, refresh, Num, HalfSec, Blink, ChangeMin=0, ChangeSec=0;
unsigned short aus_ss, an_SS;
unsigned short max_druck, druck_raw, Zone = 3;
int temp1;
char Temper[7];
void Disp_Erste_zeile(){
if(!Timer_An){
switch (Modus_Auswahl){
case 0: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, ">Pausendauer");
break;
case 1: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, ">Vacuumdauer");
break;
case 2: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, ">Druck");
break;
case 3: Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, ">Wiederholung");
break;
}
}
else{
if (Wechsel_Ventil == 1) {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, "Vacuum");
Lcd_Out(1,14, "~");
Lcd_Chr(1,15, Mbar[0,0]);
}
if (Wechsel_Ventil == 0) {
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1, "Pause");
Lcd_Out(1,14, "~");
Lcd_Chr(1,15, Num_Cycles/10+48);
Lcd_Chr(1,16, Num_Cycles%10+48);
}
}
}
void Disp_Char(unsigned short col, unsigned short chr){
Lcd_Chr(2, col, chr+48);
}
void Disp_Modus(){
for(i=0; i<2; i++){
if(Modus_Auswahl == 0){ // Mode_SELECT=0 is OFF time SELECT_sw
Lcd_Out(2,1, NA2);
Disp_Char(SS_Pos+i,Aus_Zeit[i]);
}
if(Modus_Auswahl == 1){ // Mode_SELECT=1 ist AN_Zeit
Lcd_Out(2,1, NA3);
Disp_Char(SS_Pos+i,AN_Zeit[i]);
}
if(Modus_Auswahl == 2){ // Mode_SELECT=1 ist Aus_Zeit
Lcd_Out(2,1, NA4);
Disp_Char(Mbar_Pos+i,AN_Zeit[i]);
}
if(Modus_Auswahl == 3){ // Mode_SELECT=2 ist Loop
Lcd_Out(2,1, NA5);
Disp_Char(8,Repeat_Cycle);
Lcd_Out(2,9, " ");
break;
}
}
}
void Delay_X(){
Delay_ms(300);
}
void cursor_links(){
for(j=0; j<5; j++){
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
}
void Speicher_Daten(){
EEPROM_Write(0,Aus_Zeit[0]);
EEPROM_Write(1,Aus_Zeit[1]);
EEPROM_Write(2,An_Zeit[0]);
EEPROM_Write(3,An_Zeit[1]);
EEPROM_Write(4,Mbar[0]);
EEPROM_Write(5,Mbar[1]);
EEPROM_Write(6,Repeat_Cycle);
EEPROM_Write(9,1); // Addresse 8 speicher EEPROM Write flag
}
void Lese_Daten(){
Aus_Zeit[0]=EEPROM_Read(0);
Aus_Zeit[1]=EEPROM_Read(1);
AN_Zeit[0]=EEPROM_Read(2);
AN_Zeit[1]=EEPROM_Read(3);
Mbar[0]=EEPROM_Read(4);
Mbar[1]=EEPROM_Read(5);
Repeat_Cycle=EEPROM_Read(6);
}
void deaktiviere_timer(){
INTCON = 0x00;
Wechsel_ventil = 0;
Num_Cycles = 0;
INTCON.T0IF = 0;
Timer_An = 0;
Blink = 0xff;
Modus_auswahl = 0;
Disp_erste_zeile();
Lese_Daten();
Disp_Modus();
}
void interrupt(){
Num ++;
if(Num == 18)
{
HalfSec ++;
Num = 0;
Blink = ~Blink;
if (HalfSec == 2)
{
HalfSec = 0;
ChangeSec = 1;
}
}
TMR0 = 39;
INTCON.T0IF = 0;
}
void Lese_druck (){
temp1 = sensor;
druck_raw = temp1 * 222;
}
void Pumpensteuerung (){
if(Wechsel_Ventil==0 && Entluef_Ventil == 1 && druck_raw < Mbar[0,0]){
Pumpen_relais = 1;
}
else
Pumpen_relais = 0;
}
void main () {
CMCON = 7;
TRISA = 0b00111100;
TRISB = 0b00000001;
PORTB=0;
PORTA=0;
Pumpen_Relais = 0;
Wechsel_Ventil = 0;
Entluef_Ventil = 0;
Timer_An = 0;
Get_Input = 0;
Cur_Pos = 0;
Cur_On = 0;
refresh = 0;
Num = 0;
HalfSec = 0;
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1, "Meditek");
Lcd_Out(2,1, "Prototyp V1.0");
delay_ms(1000);
i=0;
while(i<1){
Delay_X();
i ++;
}
Lcd_Cmd(_LCD_CLEAR);
Disp_erste_Zeile();
if(EEPROM_Read(9) == 1){
Lese_Daten();
}
Disp_modus();
do {
if(!MENU_sw && !Timer_An){
Delay_X();
if(!Get_Input){
Modus_auswahl = Modus_auswahl+1;
if(Modus_auswahl > 2) Modus_auswahl=0;
Disp_Erste_zeile();
Disp_modus();
}
if(Get_Input){
if(Modus_Auswahl==0){ // Set OFF time
Aus_Zeit[Cur_Pos] ++;
temp = Aus_Zeit[Cur_Pos];
switch (Cur_Pos){
case 0: if(temp > 5) Aus_Zeit[Cur_Pos]=0;
break;
case 1: if(temp > 9) Aus_Zeit[Cur_Pos]=0;
break;
case 2: if(temp > 5) Aus_Zeit[Cur_Pos]=0;
break;
case 3: if(temp > 9) Aus_Zeit[Cur_Pos]=0;
break;
}
Disp_Char(ss_Pos+Cur_Pos, Aus_Zeit[Cur_Pos]);
}
if(Modus_Auswahl==1){ // Set ON time
An_Zeit[Cur_Pos] ++;
temp = An_Zeit[Cur_Pos];
switch(Cur_Pos){
case 0: if(temp > 5) An_Zeit[Cur_Pos]=0;
break;
case 1: if(temp > 9) An_Zeit[Cur_Pos]=0;
break;
}
Disp_Char(ss_Pos+Cur_Pos, An_Zeit[Cur_Pos]);
}
if(Modus_Auswahl==2){ // Set mbar
mbar[Cur_Pos] ++;
temp = mbar[Cur_Pos];
switch(Cur_Pos){
case 0: if(temp > 9) Mbar [Cur_Pos]=0;
break;
case 1: if(temp > 9) Mbar [Cur_Pos]=0;
break;
}
Disp_Char(mbar_Pos+Cur_Pos, mbar[Cur_Pos]);
}
if(Modus_Auswahl==3){ // Set cyclic option
Repeat_Cycle ++;
if(Repeat_Cycle > 1) Repeat_Cycle=0;
Disp_Char(8, Repeat_Cycle);
}
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
} // END if(!Menu_sw)
if(!SELECT_sw && !Timer_an){
Delay_X();
Get_Input = 1;
if(Modus_Auswahl < 4) {
if(Cur_On) {
Cur_Pos ++;
if (Cur_Pos == 2) {
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Cur_Pos ++;
}
if(Cur_Pos > 2) {
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
Cur_Pos = 0;
cursor_links();
}
else Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
}
if(!Cur_On) {
Cur_On = 1;
cursor_links();
Lcd_Cmd(_LCD_UNDERLINE_ON);
}
}
else {
if(!Cur_On) {
Cur_On = 1;
for(j=0; j<7; j++){
Lcd_Cmd(_LCD_MOVE_CURSOR_LEFT);
}
Lcd_Cmd(_LCD_UNDERLINE_ON);
}
}
} // if(!SELECT_sw && !Timer_On) ends here
if(!ENTER_sw && Get_Input){
Delay_X();
Get_Input = 0;
Cur_On = 0;
Cur_Pos = 0;
Disp_modus();
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
}
if (!START_sw && !Get_Input){
Delay_X();
switch(Timer_an){
case 0:
Timer_an = 1;
Disp_erste_zeile();
OPTION_REG = 0x07;
TMR0 = 354;
INTCON = 0xA0;
INTCON.T0IF = 0;
Modus_auswahl = 0;
Blink = 0;
Disp_modus();
Speicher_Daten();
break;
case 1: deaktiviere_timer();
break;
}
}
if(Timer_an){
aus_ss = aus_zeit[0]*10 + aus_zeit[1];
an_ss = an_zeit[0]*10 + an_zeit[1];
switch(Blink){
case 0: Lcd_Chr(2,ss_Pos+2,' ');
break;
case 255: Lcd_Chr(2,ss_Pos+2,':');
break;
}
if(!aus_SS && !wechsel_ventil){
if(an_SS){
Wechsel_Ventil = 1;
Modus_auswahl = 1;
Disp_erste_zeile();
Disp_modus();
}
else {
deaktiviere_timer();
}
}
if(!an_SS && wechsel_ventil){
if(Repeat_Cycle ==1){
Wechsel_ventil = 0;
Num_Cycles++;
Pumpensteuerung();
if(Num_Cycles > 99){
deaktiviere_timer();
}
else {
lese_Daten();
Modus_auswahl = 0;
Disp_erste_Zeile();
Disp_modus();
}
}
else {
deaktiviere_timer();
}
}
if(ChangeSEC) {
switch(Modus_auswahl){
case 0: if(aus_SS == 0){
aus_SS = 59;
}
else if (aus_SS >>0)
aus_SS --;
aus_zeit[0] = Aus_ss/10;
aus_zeit[1] = Aus_ss%10;
break;
case 1: if(an_SS == 0){
an_SS = 59;
}
else if(an_SS >> 0)
an_SS --;
an_zeit[0] = an_ss/10;
an_zeit[1] = an_ss%10;
break;
}
Disp_modus();
}
}
}while(1);
}