Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
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
#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);
}
}
#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;
}
}
}
#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();
}
}
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...