Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How can I convert into Hex following Code

Status
Not open for further replies.

honey361

Newbie level 4
Joined
Apr 22, 2009
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
pakistan
Activity points
1,351
hexadecimal 64, 128, 256

Dear All,
How can I convert into Hex following Code

#include <pic.h>
#include <string.h>
#include <stdio.h>

__CONFIG(BORDIS & XT & LVPDIS & PWRTDIS & WDTDIS & WRTEN);

#define FOSC 14318180
#define FPWM 20000


unsigned char Fila1[16];
unsigned char Fila2[16];
unsigned int rpm=0,t0=0,t1=0,ie=0;


void Inicio_PWM(void)
{
// Periode PWM
PR2=(unsigned char)(FOSC/(FPWM*4.0)-1);

// Timer 2 enabled and Timer2 preescaler value = 1
T2CON=4;

// PWM mode
CCP1M3=1;
CCP1M2=1;
}

void PWM(unsigned int DUTY)
{
unsigned int tmp;

// DUTY max = FOSC/FPWM = 700
// DUTY min = 0

tmp=DUTY;
CCP1Y=((tmp & 1)==1) ? 1 : 0; // LSB DUTY (BIT 0)
tmp=DUTY;
CCP1X=((tmp & 2)==2) ? 1 : 0; // (BIT 1)
tmp=DUTY;
CCPR1L=(unsigned char)(tmp >> 2); // 8 MSB DUTY (BITS 10..2)
}


void Retardo(int N)
{
int j;

for(j=0;j<N;++j);
}


void Control_LCD(unsigned char A)
{
unsigned char tmp;

RC0=0;
RC1=0;

tmp=A;
RC7=((tmp & 128)==128) ? 1 : 0;
tmp=A;
RC6=((tmp & 64)==64) ? 1 : 0;
tmp=A;
RC5=((tmp & 32)==32) ? 1 : 0;
tmp=A;
RC4=((tmp & 16)==16) ? 1 : 0;
tmp=A;
RB1=((tmp & 8)==8) ? 1 : 0;
tmp=A;
RB2=((tmp & 4)==4) ? 1 : 0;
tmp=A;
RB3=((tmp & 2)==2) ? 1 : 0;
tmp=A;
RB4=((tmp & 1)==1) ? 1 : 0;

Retardo(500);

RC3=1;
RC3=0;
}

void Dato_LCD(unsigned char A)
{
unsigned char tmp;

RC0=0;

tmp=A;
RC7=((tmp & 128)==128) ? 1 : 0;
tmp=A;
RC6=((tmp & 64)==64) ? 1 : 0;
tmp=A;
RC5=((tmp & 32)==32) ? 1 : 0;
tmp=A;
RC4=((tmp & 16)==16) ? 1 : 0;
tmp=A;
RB1=((tmp & 8)==8) ? 1 : 0;
tmp=A;
RB2=((tmp & 4)==4) ? 1 : 0;
tmp=A;
RB3=((tmp & 2)==2) ? 1 : 0;
tmp=A;
RB4=((tmp & 1)==1) ? 1 : 0;

Retardo(500);

RC0=1;
RC3=1;
RC3=0;
}

void Inicio_LCD(void)
{
RC0=1;
RC1=1;
RC3=1;
Retardo(500); // 400
Control_LCD(56);
Retardo(500); // 100
Control_LCD(56);
Retardo(500); // 20
Control_LCD(56); // Instruction code

Control_LCD(8); // Display OFF
Control_LCD(1); // Clean display
Control_LCD(6); // Mode SET
Control_LCD(2); // Home
Control_LCD(0b00001111); // LCD ON, Cursor ON
}

void MostrarFila(unsigned char Pos,unsigned char Cadena[])
{
unsigned char j;

if(Pos==1) Control_LCD(128);
if(Pos==2) Control_LCD(192);

for(j=0;j<16;++j)
{
Dato_LCD(Cadena[j]);
}
}


void Inicio_Timer0(void)
{
T0CS = 0; // Mode Timer
T0IE = 1; // Enable Timer0 for unmasked interruptions
PSA=0; // Preescaler mode timer

/****************************************************************************************/
/* Periodo = TMR0_Rate*256/(FOSC/4) : (FOSC=14MHz) */
/* */
/* TMR0_Rate: 2 4 8 16 32 64 128 256 */
/* PS2,PS1,PS0: 000 001 010 011 100 101 110 111 */
/* Periode: 146us 292us 585us 1.17ms 2.34ms 4.68ms 9.36ms 19.4ms */
/* Frequency: 6.7kHz 3.3kHz 1.7kHz 840Hz 420Hz 210Hz 105Hz 52.5Hz */
/* */
/****************************************************************************************/

// TMR0_Rate = 4 -> T = 4*256/(14.31818e6/4) = 286.06us

PS2=0;
PS1=0;
PS0=1;
}

void interrupt isr(void)
{
if (T0IF) // Timer0 Interruption
{
++t0;
++t1;

T0IF=0;
}


if (INTF) // External clock interruption
{
++ie;

INTF = 0;
}
}

main()
{
TRISA=0b11001111;
TRISB=0b11100001;
TRISC=0b00000000;

ADCON1=0b10000000; // PORTA configured as digital I/O and RA0 as analogic input

GIE = 1; // Enable all the unmasked global interruptions
INTE=1; // Enable the external interruption RB0/INT

Inicio_PWM();
Inicio_LCD();
Inicio_Timer0();


sprintf(Fila1,"VELOCIDAD ROTOR ");

for(;;)
{
if (t1>=205) // update each 58.64ms
{
// Resolution = 60/(1024*58.64ms) -> 1 rpm

rpm=ie;
ie=0;
if (rpm>=1500) rpm=1500;

PWM((unsigned int)(rpm/2.142857)); // 1500/700 = 2.142857
sprintf(Fila2," %d (rmp) ",rpm);

t1=0;
}


if (t0>=3496) // LCD display is refreshed each second
{
MostrarFila(1,Fila1);
MostrarFila(2,Fila2);
t0=0;
}
}
}
 

how to represent 27 in hexadecimal format?

Use a compiler to compile it and you will have a hex file.
Hi-Tech C is now included wih MPLAB from Microchip.
Download MPLAB, install it, make a project, copy and paste your code into it. Compile, job done.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top