Micro C Embedede
Micro C Embedede
}
}
}
void main()
{
ADCON1=0X07;
ADCON0=0X00;
PORTB=0X00;
TRISB=0X00;
T1CON=0X01;
TMR1H = 0x80;
TMR1L=0x00;
INTCON=0XC0;
PIE1.TMR1IE = 1;
PIR1.TMR1IF = 0;
cnt=0;
while (1)
{
if(cnt==76)
{
PORTB=PORTB++;
cnt=0;
}
}
}
} */
void main()
{
ADCON1=0X07;
ADCON0=0X00;
PORTD=0X00;
TRISD=0X00;
PORTC=0X00;
TRISC=0xFF;
T1CON=0X0B;
TMR1H = 0x80;
TMR1L=0x00;
//INTCON=0XC0;
// PIE1.TMR1IE = 1;
//PIR1.TMR1IF = 0;
cnt=3;
while (1)
{
if(TMR1L==cnt)
{
PORTD.F1=1;
}
}
}
}
void main()
{
ADCON1=0X07;
ADCON0=0X00;
PORTB=0X00;
TRISB=0X00;
T2CON=0XFF;
TMR2=0;
INTCON=0XC0;
PIE1.TMR2IE = 1;
PIR1.TMR2IF = 0;
cnt=0;
while (1)
{
if(cnt>=30)
{
PORTB=PORTB++;
cnt=0;
}
}
}
}
void main()
{
OPTION_REG.F6=1;
ADCON1=0X07;
ADCON0=0X00;
PORTD=0X00;
TRISD=0X00;
PORTC=0X00;
TRISC=0xFF;
INTCON=0X90;
cnt=0;
while (1)
{
}
}
}
void main()
{
ADCON1=0X07;
ADCON0=0X00;
PORTD=0X00;
TRISD=0X00 ;
PORTB=0X00;
TRISB=0x80;
INTCON.GIE=1;
INTCON.RBIE=1;
INTCON.RBIF=0;
cnt=0;
while (1)
{
if (Button(&PORTB,7,1,1))
{
InteRupt();
}
while (PORTB & 0x80) ;
if(cnt==3)
{
PORTD.F1=1;
}
}
}
void InitMain() {
PORTB = 0; // set PORTB to 0
TRISB = 0; // designate PORTB pins as output
void main() {
initMain();
/*
* Project name:
ADC_on_LEDs (Displaying ADC result on port LEDs WITH REFERENCE RA3)
*
*/
void main() {
ADRESL=0X0C;
TRISA = 0xFF;
ADRESH=0; // Configure analog inputs and Vref
// PORTA is input
TRISD = 0x3F; // Pins RB7, RB6 are outputs
TRISC = 0;
ADCON1.F4 = 1 ; // PORTD is output
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTC = temp_res; // Send lower 8 bits to PORTD
PORTD = temp_res >> 2; // Send 2 most significant bits to RB7, RB6
} while(1);
}
/*
* Project name:
ADC_on_LEDs (Displaying ADC result on port LEDs)
* Copyright:
(c) Mikroelektronika, 2005-2008.
*/
void main() {
ADCON1 = 0x80; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISD = 0x3F; // Pins RB7, RB6 are outputs
TRISB = 0; // PORTD is output
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTD
PORTD = temp_res >> 2; // Send 2 most significant bits to RB7, RB6
} while(1);
}
/*
* Project name:
ADC_on_LEDs (Displaying ADC result on port LEDs)
* Copyright:
(c) Mikroelektronika, 2005-2008.
* Description:
The code demonstrates using library function for AD conversion. 10 bits
result is displayed on PORTB (two most significant bits) and PORTD. Notice
the changes on LEDs on portD while you you turn P1.
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC4
Oscillator: HS, 08.0000 MHz
Ext. Modules: -
SW: mikroC v8.0.0.0
* NOTES:
On EasyPIC4 jumper should be on RA2 at A-D Converter Input.
*/
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTD
PORTD = temp_res >> 2; // Send 2 most significant bits to RB7, RB6
} while(1);
}
void main() {
ADRESL=0X04;
TRISA = 0xFF;
ADRESH=0; // Configure analog inputs and Vref
// PORTA is input
TRISD = 0x3F; // Pins RB7, RB6 are outputs
TRISB = 0;
ADCON1.F4 = 0 ; // PORTD is output
do {
temp_res = ADC_Read(2); // Get 10-bit results of AD conversion
PORTB = temp_res; // Send lower 8 bits to PORTD
PORTD = temp_res >> 2; // Send 2 most significant bits to RB7, RB6
} while(1);
}
// 7 seg statics
void main() {
//OPTION_REG = 0x80; // Timer0 settings
PORTD = 0; // clear PORTA (make sure both displays are off)
TRISD = 0; // designate PORTA pins as output
PORTC = 0; // clear PORTD (make sure LEDs are off)
TRISC = 0; // designate PORTD pins as output
//TMR0 = 0; // clear TMRO
digit1 = 0x7F; // mask for 8 (7 seg. display)
digit2 = 0x4F; // mask for 3 (7 seg display)
//INTCON = 0xA0; // Enable GIE, TMR0IE
// wait for interrupt
digit_no=0;
while(1)
{
if (digit_no==0) {
PORTD = 0;
digit_no = 1;
Delay_ms(5); // turn on 1st 7 seg., turn off 2nd
} else {
PORTD = 0;
PORTC = digit1; // send mask for digit 8 to PORTD
PORTD= 2; // turn on 2nd 7 seg., turn off 1st
digit_no = 0;
Delay_ms(10); // turn on 1st 7 seg., turn off 2nd
}
//Delay_ms(1000);
}
}
unsigned short i;
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
//movable letters
char *text[5] = {'A','B','C','D'};
unsigned short int i;
void main()
{
TRISC=0X00;
PORTC=0X00;
Lcd_Config(&PORTC, 0, 1, 2, 7, 6, 5, 4);
Lcd_Init(&PORTC); // Lcd_Init_EP4, see Autocomplete
LCD_Cmd(LCD_CLEAR); // Clear display
LCD_Cmd(LCD_CURSOR_OFF); // Turn cursor off
Delay_ms(1000);
while(1)
{
for(i=0;i<=5;i++)
{
Delay_ms(100);
}
LCD_Cmd(LCD_CLEAR);
}
SPI
//SPI PROGRAM
const unsigned short _CHIP_SELECT = 1;
void main()
{
Soft_Spi_Config(&PORTC, 4, 5, 3);
TRISC &=~(_CHIP_SELECT);
TRISB=0X00;
PORTB=0X00;
while(1)
{
PORTC&=~(_CHIP_SELECT);
Delay_us(1);
Soft_Spi_Write(0XA3);
Delay_us(1);
PORTB=Soft_Spi_Read(0XA4);
Delay_us(1);
PORTC|= _CHIP_SELECT;
Delay_ms(1000);
}
// send data via UART
}
void main()
{
OPTION_REG.F5=1;
OPTION_REG.F3=1;
//ADCON1=0X07;
//ADCON0=0X00;
TRISA=0XFF;
PORTA=0X00;
PORTB=0X00;
TRISB=0X00;
TMR0=0;
//INTCON=0XA0;
}
}
void main()
{
OPTION_REG=0X30;
//ADCON1=0X07;
//ADCON0=0X00;
TRISA=0XFF;
PORTA=0X00;
PORTB=0X00;
TRISB=0X00;
TMR0=0;
//INTCON=0XA0;
//cnt=0;
while (1)
{
if(TMR0==4)
{
PORTB.F1=1;
}
}
void main() {
//ADCON1 = 0x80;
ADRESL=0X0C; // Configure analog inputs and Vref
TRISA = 0xFF; // PORTA is input
TRISD = 0x3F; // Pins RB7, RB6 are outputs
/*
* Project name:
Spi_01 (Demonstration of SPI Library usage)
* Copyright:
(c) MikroElektronika, 2005-2008
* Description:
This code demonstrates using library routines for SPI communication.
Also, this example demonstrates working with MAX7219.
Eight 7 segment displays are connected to MAX7219. MAX7219 is connected to RC0
and SDO,SDI,SCKL pins are appropriatly connected.
* Test configuration:
MCU: PIC16F877A
Dev.Board: EasyPIC4
Oscillator: HS, 08.0000 MHz
Ext. Modules: mE Serial 7-seg Display2 board on PORTC
SW: mikroC v8.0.0.0
* NOTES:
None.
*/
#include "m7219.h"
void main() {
while (1) {
for (j=0; j<10; j++)
for (i=8; i>0; i--) {
select_max(); // select max7219
Spi_Write(i); // digit No
Spi_Write(j); // digit Value
deselect_max(); // deselect max7219
Delay_ms(100);
}
}
}