Anda di halaman 1dari 9

#include <18F4550.

h>
#include <math.h>
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#fuses HS,NOPROTECT,NOWDT,NOLVP //PUT
#include "lcd.c"
#define Tiempo 200
int nnn;
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte

PORTA
PORTB
PORTC
PORTD
PORTE
TRISA
TRISB
TRISC
TRISD
TRISE

=0x80
=0x81
=0x82
=0x83
=0x84
=0x92
=0x93
=0x94
=0x95
=0x96

#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte
#byte

TOSU=0xFFF
TOSH=0xFFE
TOSL=0xFFD
STKPTR=0xFFC
PCLATU=0xFFB
PCLATH=0xFFA
PCL=0xFF9
TMR0H=0xFD7
TMR0L=0xFD6
TMR1H=0xFD9
TMR1L=0xFD4
T0CON=0xFD5
T1CON=0xFD6
bsr=0xFE0
wreg=0xFE8
status=0xFD8
RCON=0xFD0
INTCON=0xFF2

#byte ADCON0=0x1F
#bit ANALOGICO= ADCON0.3
#bit TMR0IE=INTCON.5
#bit TMR0IF=INTCON.2
#bit TMR1IE=INTCON.5
#bit TMR1IF=INTCON.2
#bit IPEN=RCON.7
int32 result=0; //numero recibido!!!!!!!!!
int const lenbuff=32; // Longitud mxima del buffer
int xbuff=0x00; // ndice: siguiente char en cbuff
char cbuff[lenbuff]; // Buffer de recepcin
int32 quantum=50; // Verificar cual es el quantum, y modificar este valor
int np=0;
int killp;
int colap[100];
int m;
int8 i;

int r=0;
int32 dirini;
//long d=1300;
int k1,k2,k3,k4;
int l1,l2,l3,l4;
int d8;
struct pcb{
int32 di;
int32 df;
int32 da;
//direccion actual TOSU TOSH TOSL
int estado;
//saber si el proceso esta cargado, descargado o ejecuta
ndose
int wreg;
//almacenamiento de datos
int status;
//almacenamiento de datos
int bsr;
//almacenamiento de datos para saber en q estado se qued
o el proceso
int id;
//identificador o numero del proceso
int32 tiem_eje;
} vpcb[7]; // del 0 al 7 por tanto 8 procesos cada proceso tiene las caracterist
icas anteriores
void activar_timer()
{
// set_timer0(65478);
//
// set_timer0(65438);
//
// set_timer0(65380);
//
// set_timer0(65341);
//
// set_timer0(65282);
//
// set_timer0(65243);
//
// set_timer0(65185);
//
// set_timer0(65146);
//
set_timer0(65048);
//
// set_timer0(64950);
//
//set_timer0(quantum);
enable_interrupts(INT_TIMER0);
}

para
para
para
para
para
para
para
para
para
para

3ms
5ms
8ms
10ms
13ms
15ms
18ms
20ms
25ms
30ms

void desactivar_timer()
{
disable_interrupts(INT_TIMER0);
}
#INT_TIMER0 //interrupcion la funcion a ejecutarse por el timer 0
void inter_quantum()
{ int i=0;
desactivar_timer();
//printf("w");
vpcb[colap[0]].wreg=wreg;
vpcb[colap[0]].da=(int32)TOSL;
vpcb[colap[0]].da=vpcb[colap[0]].da|((int32)TOSH<<8);
vpcb[colap[0]].da=vpcb[colap[0]].da|((int32)TOSU<<16);
if(np>1)
{ m=colap[0];
for(i=0;i<np-1;i++)
{colap[i]=colap[i+1];
}

colap[np-1]=m;
}
//pc=inicio_S0;
TOSL=00;
TOSH=40;
TOSU=00;
}
void commad_process(void){
int i;
char cmd[lenbuff]; // Comando
strcpy(cmd,cbuff); // Lo copio para procesarlo
for(i=0;i<xbuff;i++)
{result=result + ((cmd[i])-48)*pow(10,(xbuff-i-1))+0.1;
}
xbuff=0x00;// Borro buffer.
}
void add_2_cbuff(char c){
switch(c){
case 'D': // Enter -> Habilita Flag para procesar comando
commad_process();
break;
default: // Aade caracter recibido al Buffer
cbuff[xbuff++]=c;
}
}
#INT_RDA //interrupcion cuando se ativa el serial
void Dato_Recibido()
{
char rcvchar=0x00; // ltimo caracter recibido
//if(kbhit()){ // Si hay algo pendiente de recibir ...
rcvchar=getc(); // lo descargo y ...
add_2_cbuff(rcvchar); // lo aado al buffer.
//}
}
//***********************************************************************
//programa 1 LUCES 1
#ORG 0x1000, 0x1150
void ROML_LedA1(){
int s,f;
while(TRUE)
{
output_bit(PIN_A0,1);
for (k1=1;k1<200;++k1){for (l1=1;l1<200;++l1){}}
output_bit(PIN_A0,0);
for (k1=1;k1<200;++k1){for (l1=1;l1<200;++l1){}}
}
desactivar_timer();
vpcb[colap[0]].estado=0;
f=np-1;
for(s=0;s<f;s++)
{colap[s]=colap[s+1];
}
np--;

printf(LCD_PUTC, "\f PROCESO TERMINADO");


//pc=inicio_S0;
TOSL=00;
TOSH=40;
TOSU=00;
}
#ORG 0x1152, 0x1350
void ROML_LedA2(){
int s,f;
while(TRUE)
{
output_bit(PIN_A1,0);
for (k2=1;k2<200;++k2){for (l2=1;l2<200;++l2){}}
output_bit(PIN_A1,1);
for (k2=1;k2<200;++k2){for (l2=1;l2<200;++l2){}}
}
desactivar_timer();
vpcb[colap[0]].estado=0;
f=np-1;
for(s=0;s<f;s++)
{colap[s]=colap[s+1];
}
np--;
printf(LCD_PUTC, "\f PROCESO TERMINADO");
//pc=inicio_S0;
TOSL=00;
TOSH=40;
TOSU=00;
}
#ORG 0x1352, 0x1450
void display3(){
//int s,f;
while(TRUE)
{ output_bit(PIN_A2,0);
for (k3=1;k3<200;++k3){for (l3=1;l3<200;++l3){}}
output_bit(PIN_A2,1);
for (k3=1;k3<200;++k3){for (l3=1;l3<200;++l3){}}
}
}
#ORG 0x1452, 0x1540
void Task_LedA(void){
//int s,f;
while(TRUE)
{
output_bit(PIN_A3,0);
for (k4=1;k4<200;++k4){for (l4=1;l4<200;++l4){}}
output_bit(PIN_A3,1);
for (k4=1;k4<200;++k4){for (l4=1;l4<200;++l4){}}
}
/* desactivar_timer();
vpcb[colap[0]].estado=0;
f=np-1;
for(s=0;s<f;s++)
{colap[s]=colap[s+1];
}
np--;

printf(LCD_PUTC, "\f PROCESO TERMINADO");


//pc=inicio_S0;
TOSL=00;
TOSH=40;
TOSU=00;*/
}
#ORG 0x1550, 0x1700
void Contador(void){
while(TRUE){
nnn=1;
}
/* desactivar_timer();
vpcb[colap[0]].estado=0;
f=np-1;
for(s=0;s<f;s++)
{colap[s]=colap[s+1];
}
np--;
printf(LCD_PUTC, "\f PROCESO TERMINADO");
//pc=inicio_S0;
TOSL=00;
TOSH=40;
TOSU=00;*/
}
/*
#ORG 0x1702, 0x1900
void puerto(void) {
int s,f;
while(TRUE)
{
output_bit(PIN_B3,1);
for (k6=1;k6<200;++k6){for (l6=1;l6<200;++l6){}}
output_bit(PIN_B3,0);
for (k6=1;k6<200;++k6){for (l6=1;l6<200;++l6){}}
}
}
*/
void incrementa()
{
if (nnn==1){
d8=2;
d8--;
OUTPUT_BIT(PIN_C0,1);
Delay_ms(d8);
OUTPUT_BIT(PIN_C0,0);
Delay_ms(20-d8);
nnn=10;
}
nnn=10;
}
void decrementa()
{
if (nnn==1){
d8=2;
d8++;

OUTPUT_BIT(PIN_C0,1);
Delay_ms(d8);
OUTPUT_BIT(PIN_C0,0);
Delay_ms(20-d8);
nnn=10;
}
nnn=10;
}
//***********************************************************************
void Port_Init()
{
output_bit(PIN_A0,0);
output_bit(PIN_A1,0);
output_bit(PIN_A2,0);
output_bit(PIN_A3,0);
output_bit(PIN_B2,0);
output_bit(PIN_B3,0);
set_tris_b(0x00);//todas salidas LEDS
//set_tris_c(0b10000000);//todas salidas LEDS
set_tris_d(0x00); //SALIDAS AL LCD
set_tris_a(0x00);//todas salidas LEDS
}
void inte_Init()
{
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);//habilita interrupcion del serial rs232
}
void Config_TMR0()
{
T0CON=0b10000111;// habilita el enable del timer 0, con un preescalado de 1/2
56
}
void Config_TMR1()
{
INTCON = 0xC0;
T1CON = 1;
TMR1IF= 0;
TMR1IE= 1;
}

// Set GIE, PEIE


// Timer1 settings
// clear TMR1IF
// enable Timer1 interrupt

void Procesos_Init()
{ int i;
for(i=0;i<6;i++)
{vpcb[i].estado=0;} //todos los procesos al inicio estan descargados
}
void cargar_proceso()
{
colap[np]=r;
vpcb[colap[np]].di=dirini;
vpcb[colap[np]].estado=1;// 1=proceso cargado
vpcb[colap[np]].id=r;
vpcb[colap[np]].tiem_eje=0;

printf(" proceso ejecutandose: %i ", r);


printf("\n ");
printf(lcd_putc, "\f CARGADO: %i ", r);
np++;
r++;
}
void descargar_proceso()
{ int s,d,f;
for(s=0;s<np;s++)
{if(vpcb[colap[s]].id==killp)
{d=s;} //guarda el lugar del proceso a descargar
}
vpcb[colap[d]].estado=0;
printf(lcd_putc, "\f desc. %i ", killp);
printf(" proceso descargado : %i ", killp);
printf("\n ");
f=np-1; //lo quita de la cola de procesos, cuando se solicita descargarlo
for(s=d;s<np;s++)
{colap[s]=colap[s+1];
}
np--;
}
#ORG 0x6000, 0x6FFE
void comando_Ver_Procesos()
{
int ind=0;
int32 aux;
int ii;
char text_enviar[14]="\0"; //almacenara el texto a enviar
printf("\n");
for ( ii=0; ii<np; ii++ )
{
text_enviar[ind] = ( vpcb[colap[ii]].id+48 );
ind++;
text_enviar[ind]="-";
ind++;
aux = vpcb[colap[ii]].di;
text_enviar[ind]=
ind++;
aux = aux%1000;
text_enviar[ind]=
ind++;
aux = aux%100;
text_enviar[ind]=
ind++;
text_enviar[ind]=
ind++;

( aux/1000 + 48 );
( aux/100 + 48 );
( aux/10 + 48 );
( aux%10 + 48 );

text_enviar[ind]="-";
ind++;
text_enviar[ind] = ( vpcb[colap[ii]].estado+48 );

ind++;
text_enviar[ind]="-";
ind++;
aux = quantum*vpcb[colap[ii]].tiem_eje;
aux = aux/1000; // pasar de ms a segundos
text_enviar[ind]= ( aux/100 + 48 );
ind++;
aux = aux%100;
text_enviar[ind]= ( aux/10 + 48 );
ind++;
text_enviar[ind]= ( aux%10 + 48 );
ind++;
printf(text_enviar);
if (ii != (np-1) )
{ printf("P");
printf ("\n");
}
ind = 0;
}
printf("F");
result = 0;
printf ("\n");
}
#ORG 0x4000, 0x5FFE
void Inicio_SO()
{
int opcion;
desactivar_timer();
while (TRUE)
{
opcion=result%10;
switch(opcion)
{
case 1:{printf("\n ");dirini=(result-1)/10;cargar_proceso(); result=
0; break;}
case 2:{printf("\n ");killp=(result-2)/10;descargar_proceso(); resul
t=0; break;}
case 3:{incrementa(); result=0;break;}
case 4:{comando_Ver_Procesos();result=0;break;}
default:break;
}
if(np!=0)
{
if(vpcb[colap[0]].estado==1)
{
activar_timer();
vpcb[colap[0]].estado=2;
vpcb[colap[0]].tiem_eje++;
goto_address(vpcb[colap[0]].di);
}

if(vpcb[colap[0]].estado==2)
{
wreg=vpcb[colap[0]].wreg;
vpcb[colap[0]].tiem_eje++;
activar_timer();
goto_address(vpcb[colap[0]].da);
}
}
}
}
void main(void)
{
printf("
Conectado y Listo \n");
printf("
************************************");
// Port_Init();
Procesos_Init();
inte_Init();
Config_TMR0();
Config_TMR1();
lcd_init();
#asm
call 0x4000
#endasm
}

Anda mungkin juga menyukai