Skip to main content

Posts

Showing posts from November, 2014

PIC Programming: LED blinking using C

Circuit: Program: #include<P18F452.h> #define mybit PORTBbits.RB0 void MSDelay (unsigned int); void main() { TRISBbits.TRISB0=0; while(1){ mybit=1; MSDelay(250); mybit=0; MSDelay(250); } } void MSDelay (unsigned int itime) { unsigned int i;     unsigned char j; for(i=0;i<itime;i++) for(j=0;j<165;j++); }

PIC Programming: stepper motor interface with clockwise and anticlockwise control using C

Circuit: Program: #include<p18f452.h> #pragma config WDT=OFF #define a 100 void delay(unsigned char); void main(){ TRISB=0x00; TRISD=0x00; while(1){ if(PORTDbits.RD0==0){ PORTB = 0b00000001; delay(a); PORTB = 0b00000100; delay(a); PORTB = 0b00000010; delay(a); PORTB = 0b00001000; delay(a); } else{ PORTB = 0b00001000; delay(a); PORTB = 0b00000010; delay(a); PORTB = 0b00000100; delay(a); PORTB = 0b00000001; delay(a); } } } void delay(unsigned char time){ unsigned char i,j; for(i=0;i<165;i++) for(j=0;j<time;j++); }

PIC Programming: 00-99 7 Segment Counter using C

Circuit: Program: #include<p18f452.h> #pragma config WDT = OFF void delay(unsigned int); void main() { unsigned char led1[]={0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x3F}; unsigned char led2[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; unsigned char a,b; TRISB=0x00; TRISD=0x00; PORTB=0b10111111; PORTD=0b10111111; while(1){ for(a=0;a<=9;a++) { PORTB=led2[a]; delay(200); for(b=0;b<=9;b++) { delay(200); PORTD=led1[b]; } } } } void delay (unsigned int time){ unsigned char i,j; for(i=0;i<165;i++) for(j=0;j<time;j++); }

PIC Programming: 7 segment display interface using assembly

Circuit: Program: #include P18F452.INC R1 EQU 0X07 R2 EQU 0X08 ORG 0 CLRF TRISB L3 MOVLW 0X3F MOVWF PORTB CALL QDELAY MOVLW 0X06 MOVWF PORTB CALL QDELAY MOVLW 0X5B MOVWF PORTB CALL QDELAY MOVLW 0X4F MOVWF PORTB CALL QDELAY MOVLW 0X66 MOVWF PORTB CALL QDELAY MOVLW 0X6D MOVWF PORTB CALL QDELAY MOVLW 0X7D MOVWF PORTB CALL QDELAY MOVLW 0X07 MOVWF PORTB CALL QDELAY MOVLW 0X7F MOVWF PORTB CALL QDELAY MOVLW 0X6F MOVWF PORTB CALL QDELAY GOTO L3 QDELAY MOVLW D'200' MOVWF R1 D1 MOVLW D'250' MOVWF R2 D2 NOP NOP DECF R2,F BNZ D2 DECF R1,F BNZ D1 RETURN END

PIC programming: Interfacing DC Motor using LN293D with C programming

Circuit: Program: #include<p18f452.h> #pragma config WDT=OFF void main(){ TRISB=0x00; while(1){ PORTB=0x01; } }

PIC Programming: bipolar stepper motor interface using C

CIRCUIT: Program: #include<p18f452.h> #pragma config WDT=OFF #define a 50 void delay(unsigned char); void main(){ TRISB=0x00; while(1){ PORTB = 0b00000001; delay(a); PORTB = 0b00000100; delay(a); PORTB = 0b00000010; delay(a); PORTB = 0b00001000; delay(a); } } void delay(unsigned char time){ unsigned char i,j; for(i=0;i<165;i++) for(j=0;j<time;j++); }

PIC Programming: 7 segment display interface using C

CIRCUIT: PROGRAM: #include<p18f452.h> #pragma config WDT = OFF void delay(unsigned int); void main() { unsigned char led[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F}; unsigned char a; TRISB=0x00; while(1){ for(a=0;a<=9;a++) { PORTB=led[a]; delay(250); } } } void delay (unsigned int time){ unsigned char i,j; for(i=0;i<165;i++) for(j=0;j<time;j++); }

PIC Programming: making a port bits toggle using assembly

CIRCUIT: Program: #INCLUDE p18f452.INC ORG 0 CLRF TRISD  L1 SETF PORTD CALL DELAY CLRF PORTD CALL DELAY GOTO L1 DELAY MOVLW 0xff MOVWF 0x10 L2 DECF 0x10,F BNZ L2 RETURN END

PIC Programming: 7 Segment Dispaly using assembly

Program: #include P18F452.INC R1 EQU 0X07 R2 EQU 0X08 ORG 0 CLRF TRISB L3 MOVLW 0X3F MOVWF PORTB CALL QDELAY MOVLW 0X06 MOVWF PORTB CALL QDELAY MOVLW 0X5B MOVWF PORTB CALL QDELAY MOVLW 0X4F MOVWF PORTB CALL QDELAY MOVLW 0X66 MOVWF PORTB CALL QDELAY MOVLW 0X6D MOVWF PORTB CALL QDELAY MOVLW 0X7D MOVWF PORTB CALL QDELAY MOVLW 0X07 MOVWF PORTB CALL QDELAY MOVLW 0X7F MOVWF PORTB CALL QDELAY MOVLW 0X6F MOVWF PORTB CALL QDELAY GOTO L3 QDELAY MOVLW D'200' MOVWF R1 D1 MOVLW D'250' MOVWF R2 D2 NOP NOP DECF R2,F BNZ D2 DECF R1,F BNZ D1 RETURN END

PIC 18F452 Programming: LED blinking using assembly

Here is the basic program you need to start off with when you learn to use a microcontroller. We are using the microchip family PIC microcontroller. Which stands for Peripheral Interface Controller, PIC 18F452 is a 40 pin 8-bit microcontroller with 32 KBytes flash, 1536 Bytes of RAM and 256 Bytes EEPROM. It also boasts 4 timers, and three external interrupt pins. Coming to our first program, We will be using MPLAB for Building this project. Create a new project and select MPASM Suite for compiling. After writing the program, Dont forget to add the linker file and the source file in the source window. The linker file for the PIC 18F452 can be found in the  C:\Program Files\Microchip\MPASM Suite\LKR. search for 18f452. In this program, the Bit RB0, toggles continuously with some delay. Connect an LED to The RB0 Pin, i.e Pin 33.connect a 330E resistor in series with the LED. PROGRAM #INCLUDE p18f452.INC; CONFIG WDT=OFF; disabling the watchdog timer ORG 0; Specifing the st