0% found this document useful (0 votes)
20 views3 pages

Código Mikroc

The document defines bits and variables used to control motors and read sensor values. It initializes a LCD display and PWM module. The main loop reads the analog sensor, calculates speed as a percentage, and displays the motor direction and speed on the LCD.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Código Mikroc

The document defines bits and variables used to control motors and read sensor values. It initializes a LCD display and PWM module. The main loop reads the analog sensor, calculates speed as a percentage, and displays the motor direction and speed on the LCD.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

sbit derecha at RC1_bit;

sbit izquierda at RC0_bit;


sbit boton_derecha at RB0_bit;
sbit boton_izquierda at RB1_bit;

sbit LCD_RS at RD4_bit;


sbit LCD_EN at RD5_bit;
sbit LCD_D7 at RD3_bit;
sbit LCD_D6 at RD2_bit;
sbit LCD_D5 at RD1_bit;
sbit LCD_D4 at RD0_bit;

sbit LCD_RS_Direction at TRISD4_bit;


sbit LCD_EN_Direction at TRISD5_bit;
sbit LCD_D7_Direction at TRISD3_bit;
sbit LCD_D6_Direction at TRISD2_bit;
sbit LCD_D5_Direction at TRISD1_bit;
sbit LCD_D4_Direction at TRISD0_bit;

float velocidad;
float dato;
char texto[5];
unsigned int codigo;

void floattostr_(float x, unsigned char *str,char precision)


{
/* converts a floating point number to an ascii string */
/* x is stored into str, which should be at least 30 chars long */
int ie, i, k, ndig;
double y;
ndig = ( precision<=0) ? 7 : (precision > 22 ? 23 : precision+1);
ie = 0;
/* if x negative, write minus and reverse */
if ( x < 0)
{
*str++ = '-';
x = -x;
}
/* put x in range 1 <= x < 10 */
if (x > 0.0) while (x < 1.0)
{
x *= 10.0; // a la place de =*
ie--;
}
while (x >= 10.0)
{
x = x/10.0;
ie++;
}
ndig += ie; // a la place de =+
//round. x is between 1 and 10 and ndig will be printed to
// right of decimal point so rounding is ...
for (y = i = 1; i < ndig; i++)
y = y/10.;
x += y/2.;
if (x >= 10.0) {x = 1.0; ie++;}
if (ie<0)
{
*str++ = '0'; *str++ = '.';
if (ndig < 0) ie = ie-ndig;
for (i = -1; i > ie; i--) *str++ = '0';
}
for (i=0; i < ndig; i++)
{
k = x;
*str++ = k + '0';
if (i == ie ) *str++ = '.';
x -= (y=k);
x *= 10.0;
}
*str = '\0';
}

void main() {

ANSEL =0X01;
ANSELH=0X00;

TRISA=0X01;
TRISB=0X03;
TRISD=0X00;
TRISC=0X00;
PORTC=0X03;

PWM1_Init(489);
PWM1_Start();
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

while(1)
{

if(boton_derecha==1)
{
while(boton_derecha==1)
{}
derecha=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,10,"Right");
izquierda=1;
}

if(boton_izquierda==1)
{
while(boton_izquierda==1)
{}
izquierda=0;
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,10,"Left");
derecha=1;
}

codigo=ADC_Read(0);
velocidad = ((codigo*255.0)/1023.0);
PWM1_Set_Duty(velocidad);
dato = (velocidad*100.0)/255.0;
floattostr_(dato,texto,2);
Lcd_Out(1,1,"Sentido:");
Lcd_Out(2,1,"Velocidad:");
Lcd_Out(2,11,texto);
}
}

//CODIGO POR BRYAN CANTÉ//

You might also like