⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tutor.c

📁 avr Rtos 255 Task avr Rtos 255 Task
💻 C
字号:
/**************************************************
 *
 * IAR EMBEDDED WORKBENCH TUTORIAL
 * C tutorial. Print the Fibonacci numbers.
 *
 * Copyright 1996 - 2003 IAR Systems. All rights reserved.
 *
 * $Revision: 1.2 $
 *
 **************************************************/

#include <inavr.h>

#include "Tutor.h"
//#include "taxi_avr.h"
#include "ma_io.h"
#include "ma_tmr.h"
//#include "my_os2.h"
#include "my_os.h"
//#include "ma_usart.h"
#include<string.h>

#define DIM_MENIU_TAXI  4
#define DIM_MENIU_MES   3
//#include "global.h"
//#include "ma_usart.h"
  /* Global call counter */

//int call_count;
//unsigned char a[10];


//int timp_delay;
//unsigned char debug_t;

//unsigned char t_sph,t_spl;
unsigned char i;
extern unsigned char t_sph,t_spl;
extern unsigned int global_inc;
extern unsigned char b_start_so;
extern signed char lcd_sem;
extern unsigned char ig,jg,kg,lg,mg,ng,temp_g;
extern unsigned char semtst1;
extern unsigned char semtst2;
extern unsigned char tast_ap1;
extern unsigned char tast_ap2;
extern unsigned char meniu;
extern unsigned char regim;
extern unsigned char contor_meniu;
extern unsigned char port_c;
extern unsigned char bufser;
extern unsigned char sesiune;
unsigned char schimba;
extern int led;
extern  int b;
extern unsigned int inc;
unsigned char aux;
static char screenpos[4][20] = {
                                {0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
                                 0x8A,0x8B,0x8C,0x8D,0x8E,0x8F,0x90,0x91,0x92,0x93},
                                {0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,
                                 0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3},
                                {0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,
                                 0x9E,0x9F,0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7},
                                {0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,
                                 0xDE,0xDF,0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7}
                               };
char *text1 = "Valy  ********";
char *text2 = "Barbu!!!!";

void delay(int t)
{inc=0;
  do{
  }
  while(inc<t);
}

void temp()
{
  int temp_g;
   //dezactivare LCD
  MA_WritePort_IO(MA_PORTG,0x00,0x04);//0xx
  //scriere 0 linii
  MA_WritePort_IO(MA_PORTA,0x00,0xFF);//data=0
  MA_SetPortIn_IO(MA_PORTA,0xFF);//setare port intrare
  //configurare citire LCD comanda
  MA_WritePort_IO(MA_PORTG,0x02,0x07);//010//configurare citire

 for(temp_g=0;temp_g<50;temp_g++);//temporizare
  MA_WritePort_IO(MA_PORTG,0x04,0x04);//1xx
  // //activare LCD
  //  MA_WritePort_IO(MA_PORTG,0x00,0x04);
  ///////////////////////////////////////////////////debugbuton

 do{
 //citire busy flag
  temp_g=MA_ReadPort_IO(MA_PORTA);
 }while(temp_g&0x80);
 //MA_WritePort_IO(MA_PORTE,0xFF,0xFF);//data
 MA_WritePort_IO(MA_PORTG,0x00,0x04);//000
 for(temp_g=0;temp_g<50;temp_g++);//temporizare
  MA_WritePort_IO(MA_PORTG,0x00,0x07);//000
  MA_SetPortIn_IO(MA_PORTG,0x07);//setare port intrare
}

void send_command (const char s)
{
  int temp_g;
  MA_WritePort_IO(MA_PORTG,0x00,0x07);  //000
  MA_SetPortOut_IO(MA_PORTA,0xFF);//setare port B iesire
  MA_SetPortOut_IO(MA_PORTG,0x07);//setare port G iesire

  MA_WritePort_IO(MA_PORTA,s,0xFF);//comanda
  MA_WritePort_IO(MA_PORTG,0x04,0x07);  //100
  for(temp_g=0;temp_g<50;temp_g++);//temporizare
  //temp();
}

void send_char (const char s)
{
  int temp_g;
  MA_WritePort_IO(MA_PORTG,0x00,0x07);  //000
  MA_SetPortOut_IO(MA_PORTA,0xFF);//setare port B iesire
  MA_SetPortOut_IO(MA_PORTG,0x07);//setare port G iesire

  MA_WritePort_IO(MA_PORTA,s,0xFF);//data
  MA_WritePort_IO(MA_PORTG,0x05,0x07);  //101 scriere data
  for(temp_g=0;temp_g<50;temp_g++);//temporizare
  temp();
}

void init()
{
//init_LCD();
  int temp_g;
  int ig;
  //initializare lcd
  MA_SetPortOut_IO(MA_PORTG,0x07);//setare port G iesire
  MA_SetPortOut_IO(MA_PORTA,0xFF);
  //MA_WritePort_IO(MA_PORTG,0x00,0x07);  //000

  MA_WritePort_IO(MA_PORTG,0x04,0x07); //E=1 enable
  for(temp_g=0;temp_g<200;temp_g++);//temporizare

  temp();
  for(ig=0;ig<3;ig++)
  {
   send_command(0x3c);//function Set : 8bits 2line on
   for(temp_g=0;temp_g<200;temp_g++);//temporizare
  }
   send_command(0x0F);//Display on
   for(temp_g=0;temp_g<200;temp_g++);//temporizare

   send_command(0x01);//Display clear
   for(temp_g=0;temp_g<200;temp_g++);//temporizare

   send_command(0x06);//Entry mode select
   for(temp_g=0;temp_g<200;temp_g++);//temporizare

 //  MA_WritePort_IO(MA_PORTE,0xFF,0xFF);//data

  // send_command(0x0f);//Display on
   //for(temp_g=0;temp_g<200;temp_g++);//temporizare
//End initializare
}

void send_string (char *str) {			// sends the whole string to LCD
 while ((*str != 0)&& (*str != 10)) send_char (*str++);
}

void setpos (char x,char y) {
 send_command (screenpos[x-1][y-1]);
};

void clrscr (void) {
 send_command (0x01);
};


void ftask1(void)
{
  for(;;){
//MA_SetPortOut_IO(MA_PORTF,0xFF);
//MA_WritePort_IO(MA_PORTF,0xFF,0xFF);
  }
}

//task 2: se ocupa de afisarea dinamica pe LCD
void ftask2(void)
{
for(;;){
  while((b&0x80)==0x80){
  b=MA_ReadPort_IO(MA_PORTE);
  if((b&0x80)==0x00) delay(5);
  }
  while((b&0x80)==0x00){
  b=MA_ReadPort_IO(MA_PORTE);
  if((b&0x80)==0x80)delay(5);
  }
  led=~led;
  MA_WritePort_IO( MA_PORTB, led, 0x01 );
  if(aux==0) aux=1;
  else aux=0;
  schimba=1;
}
}



void ftask3(void)
{

  //if(aux==0)send_string(text1);
  //else send_string(text2);
  for(;;){
  if(schimba==1){
    if(aux==0)send_char('a');
    else send_char('b');
    schimba=0;
    //if(aux==0)send_string(text1);
    //else send_string(text2);
  }

  }

}

void ftask4(void)
{
for(;;);
}

//main
void main(void)
{
//initializari variabile
 global_inc=0;
 meniu =0 ;//meniu
 regim = 0;//regimul liber
 contor_meniu = 0;//contor meniu
 aux=0;

//initializari porturi IO
 MA_Init_IO();
 //MA_WritePort_IO(MA_PORTB,0XFE,0xFF);
 //MA_SetPortIn_IO(MA_PORTC,0XFF);//configurare port C intrare
 //MA_SetPortIn_IO(MA_PORTE,0x10);//configurare port E pin 4 intrare
// MA_WritePort_IO(MA_PORTA,0X55,0xFF);
MA_SetPortIn_IO( MA_PORTE, 0xFF );
  MA_SetPortOut_IO(MA_PORTB, 0xFF );
  MA_SetPortOut_IO(MA_PORTD, 0xFF );
init();
 MA_Init_TMR();//initializare Timer
 MA_Reset_TMR();//resetare timer
 MA_Start_TMR(0,1);//pornire timer 0
 global_inc=0;
 b_start_so=0;
 aux=1;
 schimba=1;
 __enable_interrupt(); /* set global interrupt enable */
 //////////////////////////taxi


//initializari la pornirea SO
 semtst1 = 0;
 semtst2 = 0;
 global_inc=0;
 start_so();//porneste sistemul de operare (kernelul)


 creaza_task(ftask1,10);
 creaza_task(ftask2,100);
 creaza_task(ftask3,100);
 creaza_task(ftask4,10);
//initializeaza primul task
 init_task();
 pop_var();
 PopSP();

/////////////////////////////////////

////////////////////////////////////

 while(1)
 {
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -