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.

Hello i want to start pic programming with Hitech c can any one help me

Status
Not open for further replies.

picmicroh

Newbie level 3
Newbie level 3
Joined
Apr 10, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,310
Hello i want to start pic16 programming with Hitech c can any one help me

i know assembly programming
 

Program in Assembly
Code:
del1	equ		0x20
del2	equ		0x21
#include <p16f877a.inc>
LIST p=16f877a
__config 3f39
			org		0x00
Start		goto	main
main		call	sys_init
			call	blink_LED

blink_LED	movlw	0xff
			movwf	PORTD
			call	delay
			clrf	PORTD
			call	delay
			goto	blink_LED

		
delay		movlw	.200
			movwf	del1
			movlw	.255
			movwf	del2
s1			decfsz	del1,f
			goto	s
			return
s			decfsz	del2,f
			goto	$-1
			goto	s1

sys_init	clrf	PORTD
			banksel	TRISD
			clrf	TRISD
			banksel	PORTD
			return
end

Program in HI-TECH C

Code:
#include <htc.h>
#define _XTAL_FREQ 4000000 // 4 MHz clock 

__CONFIG(0X3F39);

void main(){
TRISD = 0;

while(1){

PORTD = 0XFF;
__delay_ms(175);
__delay_ms(175);
PORTD = 0X00;
__delay_ms(175);
__delay_ms(175);

}



}

Both out put of above programs are same
Hopefully helps for start
 
1. download mplabX
2. download hitech compiler depending upon the microcontroller you want to use...(16f or 18f series), lite version is enough....
3. start a new project in mplabX and select Hitech C as a compiler...
4. add a c source file to the project....
5. include htc.h
6. u need to set configuration bits of microcontroller....(this can be done in various ways...see the codes given below..) also check out the doc folder in your hitechc compiler directory...
7. now Configure SFR, which also controls microcontroller
8. Write your code n Enjoy... ;)

Note: Don't go by the logic....just have a look at syntax....

here is a simple code for 16f series
Code:
#include "htc.h"
#define _XTAL_FREQ 4000000

__CONFIG(FOSC_XT & WDTE_OFF& PWRTE_OFF & BOREN_OFF & LVP_OFF & WRT_OFF & CP_OFF);

#define status PORTDbits.RD1
#define out PORTDbits.RD4
#define trig PORTDbits.RD5
#define dtrig PORTDbits.RD6
#define pin5 PORTBbits.RB5
#define timer_val 179  // 161-CRO, 157-FC
#define timer2_val 50
#define timer2_val2 75
#define pul 4000
void delay(int x);
void uart_init(void);
void TX();

unsigned int pulse=0;
char cc=0x80,tt=0,end=0,t_data=0,data_en=0,sig_tx=0;
char di=0,data[10],high=0;



void interrupt ISR(void)
{
    if(TMR2IF==1)
    {
        dtrig=high;
        TMR2ON=0;
        TMR2IF=0;
    }
    else
    {
        if(T0IF==1)
        {
        if(data_en==1)
        {
            if(tt==0 )
            {
                high=1;
                TMR2=timer2_val;
                TMR2ON=1;
            }
            if(tt<8*bytes)
            {
                TMR0=timer_val;
                T0IF=0;

                if(data[di] & cc)
                    {out=1;trig=1;}
                else
                    {out=0;trig=1;}
                cc=cc>>1;
                tt++;
                if(tt==8)
                {
                    cc=0x80;
                    di++;
                }

            }
            else
            {
                TMR2=timer2_val2;
                TMR2ON=1;
                high=0;
                trig=0;
                end=1;
                out=0;
                T0IE=0;
            }
        }

        if(data_en==0)
        {
            if(pulse<(2*pul))
            {
            TMR0=timer_val;
            out=~out;
            pulse++;
            T0IF=0;
            
            if(pulse>=(2*pul))
                {
                data_en=1;
                cc=0x80;
                tt=0;
                }
            }
        }
        }

        if(RCIF==1)
        {

            t_data=RCREG;
            data[di]=t_data;
            di++;
            if(di>=bytes)   // CHNAGE No. of Bytes
            {
                sig_tx=1;
                PORTA=~PORTA;
            }
        }
    }
}


void uart_init(void)
{

}

void TX()
{
    pulse=0;
    data_en=0;
    end=0;
    out=0;
    dtrig=0;
    trig=0;
    status=1;
    TMR0=timer_val;
    T0IF=0;
    T0IE = 1;                 //Enable Global Interrupt
    pin5=1;
    while(end==0);
    pin5=0;
    out=0;
    T0IE=0;

    //__delay_ms(1000);
    status=0;
    //PORTB=0x0F;
    sig_tx=0;
}


main()
{
    char z;
    ADCON1=0x06;             // Making PORTA DIGITAL
    OPTION_REGbits.T0CS=0;  // Enabling Trigger
    OPTION_REGbits.PSA=1;   // Prescaler off
    GIE=1;
    T0IF = 0;               // Interrupt flag
    T0IE = 0;                //Enable RB0/INT external Interrupt
    PEIE=1;
    RCIE = 1;
    TMR0=timer_val;
    T2CON=0;
    TMR2IE=1;
    TMR2=timer2_val;
    TRISA=0;
    PORTA=0;
    TRISB=0;
    TRISC=0xFF;
    TRISD=0b10001101;
    trig=0;
    dtrig=0;
    out=0;

    TXSTA=0x24;
    SPBRG=25;           //9600 baud rate for 4 MHz crystal  //15 for 10MHz
    RCSTA=0X90;

    for(char i=0;i<6;i++)
    {
        status=~status;
        __delay_ms(500);
    }
    //T0IE=1;
    PORTB=0;
    status=0;
    while(1)
    {
        if(sig_tx==1)
        {
            out=0;
            di=0;
            TX();
            di=0;
            out=0;
        }
    }
}

here is a simple code for 18f series
Code:
#define _XTAL_FREQ 8000000
// LCD
#define lcd_port    PORTB
//LCD Registers addresses
#define LCD_EN      0x20 // EN=PB5
#define LCD_RS      0x10 // RS=PB4

// Includes
#include "htc.h"
#include "stdio.h"
#include "misc.h"
#include "LCD.h"
#include "ADC.h"
#include "DAC.h"
#include "test.h"

// Configuration
#pragma config IESO=OFF, OSC=INTIO67, BOREN=OFF, PWRT=OFF, WDT=OFF, PBADEN=OFF, LPT1OSC=OFF, MCLRE=ON
#pragma config DEBUG=OFF, STVREN=ON, LVP=OFF



//TEST Signals
#define check PORTBbits.RB6

int main()
{
    OSCCON=0x70; // 00 for 31khz   70for8MHz  60for4MHz  40for1MHz
    //OSCTUNE=OSCTUNE | 0x40;
    //PLLEN=1;
    ADCON0=0x01;
    ADCON1=0x0A;
    ADCON2=0x88;
    TRISD=0;
    PORTD=0;
    TRISB=0;
    PORTB=0;
    TRISC=0;
    PORTC=0;
    TRISE=0;
    PORTE=0;
        
    //vth(250);

    char str[10];
    float v_analog, gm_value=0;
    
    
    while(1)
    {
        start();
        DAC_init();
        lcd_init();
        lcd_cmd(0x82);
        lcd_str("MOSFET PARAMETERS");


        rds_test();

        gm(5);
        
/*
        check=1;
        DAC('B',2);
        check=0;
        DAC('B',1);
        check=1;
        __delay_us(10);
        check=0;
        DAC('B',2.5);
        DAC('B',0);
  */
         //;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        while(1)
        {
            v_analog=ADC(3);
            lcd_cmd(0xDF);
            lcd_str("Va=");
            sprintf(str,"%5.3f",v_analog);
            lcd_str(str);
            ms(800);
        }

        ends();
    }
}
 
mikroe compilers are also good for starting... they include many libraries for simple tasks. like led lcd dot matrix...

but if you want to learn deeply you have to go for mplabx...
 

you can always take a comfortable path.....but if you really want to learn a thing just go by the harsh path....
mplab & hitechc & micro datasheet will do the magic...
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
you can always take a comfortable path.....but if you really want to learn a thing just go by the harsh path....
mplab & hitechc & micro datasheet will do the magic...

yes he is right... if you want to save your time or you are just doing hobby projects.. go to microc... and if you wanna learn deply.. go for mplB+HITECH+DATASHEET..

F.Y.I. in HItech installation folder you can find various examples for basic tasks like... timers ports interrupts... etc..
 

Re: Hello i want to start pic16 programming with Hitech c can any one help me

Thanks nikhilsigma, ec_nisarg, PA3040

i all ready works with LCD(hd44780),7 segment display etc. by assembly. can you help me by "c code" of these types.

regards

Picmicroh
 

start by writing simple c codes for turning leds ON & OFF, put in some delays, etc...play around with microcontroller....

after that send data, whatever required by the peripheral device....

good reference to LCD programming...
 

Check out this **broken link removed**.

It uses MPLAB, Hi-Tech C, and PICkit2
 

programming into c is not a big deal as you may think.. if you can write program in ANSI well you can program a micro in C too..
in embedded C you have some special variables (SFRs) that control the micro. program in the same way as you might have learned in your school C subject..
develop your own logic and see what happens in micro. better you buy a debugger and a demo board. or (make one for your own).

- - - Updated - - -

programming into c is not a big deal as you may think.. if you can write program in ANSI well you can program a micro in C too..
in embedded C you have some special variables (SFRs) that control the micro. program in the same way as you might have learned in your school C subject..
develop your own logic and see what happens in micro. better you buy a debugger and a demo board. or (make one for your own).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top