Sample Code Library

External interrupt For CSS Compiler

#include <16F877.h> #device adc=8 #fuses XT,NOWDT,NOPROTECT,NOLVP #use delay(clock=4000000) #INT_EXT void EXT_ISR(void){ output_toggle(PIN_B7); delay_us(300); } void Init_MCU(void){ enable_interrupts(GLOBAL); enable_interrupts(INT_EXT); ext_int_edge(H_TO_L); set_tris_B(0x01); output_low(pin_B7); } void main(){ Init_MCU(); while (TRUE) { output_toggle(PIN_B6); delay_ms(1000); } }  

Basic input-output For CSS Compiler

#include <16F877.h> #device adc=8 #FUSES NOWDT ,XT #use delay(clock=4000000) void main() { set_tris_a(0xff); set_tris_b(0x00); setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); output_b(0x00); while(true){ if(!input(pin_a0)){ output_b(0xff); delay_ms(100);} if(!input(pin_a1)){ output_b(0x00); delay_ms(100);} } }

Seven segment display 4 digit For CSS Compiler

#include <16F877.h> #device adc=8 #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use delay(clock=4000000) #define sw_up pin_a0 // SWITCH UP #define sw_down pin_a1 // SWITCH DOWN INT16 COUNT; int8 A,B,C,D; //int8 segment[10] ={ 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//common anode int8 num[10] ={ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x6F};//common cathode 0 1 2 3 4 5 6 7 8 9 // 0 1 2 …

Seven segment display 4 digit For CSS Compiler Read More »

Stepping Motor Control For CSS Compiler

#include <16F877.h> #fuses XT,NOLVP,NOWDT,NOPROTECT #use delay(clock = 4000000) #use fast_io(A) #use fast_io(B) byte num[5] = {0x00,0x01,0x02,0x04,0x08}; int8 disp,i; void Forward(){ for(i=0; i<=4;i++){ disp =num[i]; output_b(disp); delay_ms(200); } } void Backward(){ for(i=4;i>0;i–){ disp =num[i]; output_b(disp); delay_ms(200); } } void Stop(){ disp =0; output_b(disp); delay_ms(50); } void main(){ setup_adc(adc_off); set_tris_a(0xFF); set_tris_b(0B00000000); stop(); while(true){ if(!input(pin_a0)){ do{ Forward(); } …

Stepping Motor Control For CSS Compiler Read More »

I2C bus for 24LC16 For CSS Compiler

  #include <16F877.h> #device adc=8 #FUSES NOWDT ,XT #use delay(clock=4000000) #use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3) #INCLUDE “LCD_4BIT.C” #include “I2C_24LCxx.c ” int8 value,setpoint=112; void main(){ setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); set_tris_c(0B10000000); // 1000 0000 PortC set_tris_d(0B00000000); // 0000 0000 Portd is Output lcd_init(); Write_eeprom_24LCxx(0x01,setpoint); lcd_init(); lcd_ROW_COL(1,0); // defind ddram address for put string lcd_putc(” KCHI_MICRO.PIC”); lcd_ROW_COL(2,0); lcd_putc(“READ EEPROM …

I2C bus for 24LC16 For CSS Compiler Read More »

Shift left – shift right value For CSS Compiler

#include <16F877.h> #device adc=8 #FUSES NOWDT ,XT #use delay(clock=4000000) int8 x,k; void main() { setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); set_tris_b(0x00); output_b(0); k=0; x=0x01; while(true) { for(k=0;k<=7;++k){ output_b (x); delay_ms(150); shift_left(&x,1,0); } x = 0x80; k = 0; for(k=0;k<=7;++k){ output_b (x); delay_ms(150); shift_right(&x,1,0); } x = 0x01; k = 0; } }

Analog to digital 8 bits For CSS Compiler

  #include <16F877.h> #device adc=8 #FUSES NOWDT ,XT #use delay(clock=4000000) #include <Lcd_4bit.c> int8 value; void main() { setup_adc_ports(AN0_AN1_AN3); setup_adc(ADC_CLOCK_DIV_2); setup_psp(PSP_DISABLED); setup_spi(SPI_SS_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); set_adc_channel(0); set_tris_d(0x00); set_tris_A(0xff); Lcd_init(); while(true){ set_adc_channel(0); delay_ms(10); value = read_adc(); // 0-1023 Lcd_row_col(1,0); Lcd_putc(“setpoint=”); hex_bcd(value);lcd_row_col(1,9);sent_Lcd(); delay_ms(50); } }

LCD Module Display 4 line For CSS Compiler

#include <16F877.h> #device adc=8 #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use delay(clock=4000000) #include <Lcd_4bit.c> int16 value1,value2,value3,value4; void main(){ setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); set_tris_d(0x00); lcd_init(); lcd_row_col(1,0); lcd_putc(“Electrical Power”); delay_ms(20); lcd_row_col(2,0); lcd_putc(“Loei Technical “); delay_ms(20); lcd_row_col(3,0); lcd_putc(“www.kchimicro “); delay_ms(20); lcd_row_col(4,0); lcd_putc(“Pic controller “); delay_ms(5000); lcd_Clear(); lcd_init(); while(true){ value1 = 2568; value2 = 1278; value3 = 8887; …

LCD Module Display 4 line For CSS Compiler Read More »

LCD Module Display 2 line For CSS Compiler

#include <16F877.h> #device adc=8 #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use delay(clock=4000000) #include <Lcd_4bit.c> int16 value,value1; void main(){ setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); set_tris_d(0x00); lcd_init(); lcd_row_col(1,0); lcd_putc(“Electrical Power”); delay_ms(20); lcd_row_col(2,0); lcd_putc(“Loei Technical “); delay_ms(5000); lcd_Cls(); while(true){ value = 2568; value1 = 1278; //================================== lcd_row_col(1,0); Lcd_putc(“setpoint=”); hex_bcd(value);lcd_row_col(1,9);sent_Lcd(); //delay_ms(100); //================================== lcd_row_col(2,0); Lcd_putc(“Value=”); hex_bcd(value1);lcd_row_col(2,6);sent_Lcd(); delay_ms(100); } }