Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************
- Main program
- *******************************************************/
- // Includes
- #include <float.h>
- #include <math.h>
- #include "ioADUC841.h"
- #include "LCD.h"
- #include <stdio.h>
- #include "Commun.h"
- #define kaire 0
- #define desine 1
- // Global variables
- signed long e=0,vel=5;
- unsigned long i=0;
- float max=0,min=5000;
- unsigned int vid[15], nu =4,leds=0;
- unsigned char a=0;
- unsigned char n=0;
- unsigned char b=0;
- unsigned char mas[10];
- // Functions prototypes
- void WD_refresh(void);
- void Init(void);
- void ADC_Init(void);
- //-------------------------------------------------------------------------------------------
- /* Main program */
- //--------------------------------------------------------------------------------------------
- int main(void)
- {
- Init();
- ADC_Init();
- LCD_init();
- delay_LCD(500);
- SetLcdAdres (0x80);
- delay_LCD(500);
- priintLCD("Velinimas (ms)");
- while(1) // endless loop
- {
- e=0;
- for(i=0; i<15; i++){
- e=e+vid[i];
- }
- e=(5000.0/(max-min+1))*(e/15-min+1)-2500;//ribos -2500~2500
- sprintf(mas,"=%d ms",(signed int)e);
- SetLcdAdres (0xC0);
- delay_LCD(500);
- priintLCD(mas);
- WD_refresh();
- leds=1<<nu;
- Rg07=leds;
- }
- }
- void WD_refresh(void)
- {
- CS6=0xff;
- CS6=0;
- }
- // Interrupt processing if TF0 appears
- #pragma vector=TF0_int
- __interrupt void TF0_interupt(void)
- {
- TCON&=0xEF;// atejus pertraukimui, stabdyti laikmati
- TL0=0x87; // nustatyti pradines reikmes: jaun. baitas; 20.2ms
- TH0=0x96; // ir vyr. baitas
- TCON|=0x10;// vel paleisti laikmati
- if(vel==0){
- if(e<0){
- vel=-e/20+5;
- if(nu==0){
- nu=8;
- }
- nu--;
- }
- else{
- vel=e/20+5;
- nu++;
- if(nu==8){
- nu=0;
- }
- }
- }
- else{
- vel--;
- }
- }
- // Interrupt processing if EOC appears
- #pragma vector=ADCI_int
- __interrupt void ADC_interupt(void)
- {
- vid[n]=(((unsigned int)(ADCDATAH & 0x0F)<<8)+(unsigned int)ADCDATAL);
- if(max<vid[n]){
- max=vid[n];
- }
- if(min>vid[n]){
- min=vid[n];
- }
- n++;
- if(n==15)
- {
- n=0;
- }
- }
- // CPU initialization
- void Init(void)
- {
- TMOD=0x01; // Nustatyti laikmacio darbo retima
- TL0=0x87; // nustatyti pradines reikmes: jaun. baitas;
- TH0=0x96; // ir vyr. baitas
- TCON_bit.TR0=1; // paleisti laikmati
- IE_bit.EA=1; // leisti visas pertrauktis
- IE_bit.ET0=1; // leisti pertraukti pagal TF0
- IE_bit.ET1=0; // drausti pertraukti pagal TF1
- IE_bit.EX0=0; // drausti pertraukti pagal int0
- IE_bit.EX1=0; // drausti pertraukti pagal int1
- return;
- }
- /* ADC initialization */
- void ADC_Init(void)
- {
- ADCCON1=0x8C;
- ADCCON2=0x20;
- IE_bit.EADC=1;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement