/Designs/ROBOTS/SSP01A/SW/PIC18F4550/main.c
0,0 → 1,85
#include "main.h"
 
#define LED1 PIN_A1
#define LED2 PIN_A2
 
int8 lsb, msb;
signed int16 pwm;
 
#int_SSP
void SSP_isr(void)
{
int8 state;
state = i2c_isr_state();
if (state == 0)
{
i2c_read();
}
if (state == 1)
{
lsb = i2c_read();
}
if (state == 2)
{
output_low(LED2);
msb = i2c_read();
pwm = MAKE16(msb,lsb);
if (pwm==0)
{
set_pwm1_duty(0);
set_pwm2_duty(0);
}
if (pwm>0)
{
set_pwm1_duty(pwm);
set_pwm2_duty(0);
}
if (pwm<0)
{
set_pwm1_duty(0);
set_pwm2_duty(abs(pwm));
}
}
}
 
 
void main()
{
setup_oscillator(OSC_8MHZ|OSC_INTRC);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_2);
setup_psp(PSP_DISABLED);
//!!! setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_16,255,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
// setup_ccp1(CCP_PWM_FULL_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L);
setup_ccp1(CCP_PWM);
setup_ccp2(CCP_PWM);
// set_pwm1_duty(512);
// set_pwm2_duty(512);
set_pwm1_duty(0);
set_pwm2_duty(0);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
 
printf("Cvak.\r\n");
pwm=0;
//Example blinking LED program
while(true){
printf("Hmm...%Ld\r\n",pwm);
output_low(LED1);
delay_ms(500);
output_high(LED1);
output_high(LED2);
delay_ms(500);
}
 
}
/Designs/ROBOTS/SSP01A/SW/PIC18F4550/main.h
0,0 → 1,39
#include <18F4550.h>
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOBROWNOUT //No brownout reset
#FUSES BORV20 //Brownout reset at 2.0V
#FUSES PUT //Power Up Timer
#FUSES NOCPD //No EE protection
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES IESO //Internal External Switch Over mode enabled
#FUSES FCMEN //Fail-safe clock monitor enabled
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#FUSES NOCPB //No Boot Block code protection
#FUSES MCLR //Master Clear pin enabled
#FUSES LPT1OSC //Timer1 configured for low-power operation
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES PLL12 //Divide By 12(48MHz oscillator input)
#FUSES CPUDIV1 //System Clock by 4
#FUSES USBDIV //USB clock source comes from PLL divide by 2
#FUSES VREGEN //USB voltage regulator enabled
#FUSES ICPRT //ICPRT enabled
#FUSES CCP2C1
 
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8,errors)
#use i2c(SLAVE, Fast, sda=PIN_B0, scl=PIN_B1, force_hw, address=0xA2)
 
 
/Designs/ROBOTS/SSP01A/SW/PIC18F4550/main.hex
0,0 → 1,73
:0400000098EF01F084
:08000800046ED8CF05F0E0CF33
:1000100006F00001E9CF0CF0EACF07F0E1CF08F0DD
:10002000E2CF09F0D9CF0AF0DACF0BF0F3CF12F01C
:10003000F4CF13F0FACF14F0F5CF15F0F6CF16F099
:10004000F7CF17F000C00EF001C00FF002C010F0A3
:1000500003C011F09DA630EF00F09EB657EF00F000
:100060000EC000F00FC001F010C002F011C003F08C
:100070000CC0E9FF07C0EAFF078E08C0E1FF09C016
:10008000E2FF0AC0D9FF0BC0DAFF12C0F3FF13C0B2
:10009000F4FF14C0FAFF15C0F5FF16C0F6FF17C035
:1000A000F7FF045006C0E0FF05C0D8FF1000C7BA34
:1000B00003D01D6AC7B41D8E1D501D2A286E2852FC
:1000C00005E1C69C9EA6FED7C950C688282C06D03E
:1000D000C69C9EA6FED7C950C688196E2850020835
:1000E00050E192948994C69C9EA6FED7C950C688BA
:1000F0001A6E1AC01CF019C01BF01B5204E11C52EE
:1001000002E1BE6ABB6A1CBE19D01C5203E11B503F
:10011000000814E21CC002F01BC001F002320132E0
:1001200002320132023201C0BEFF02320230300B15
:10013000006EBD50CF0B0010BD6EBB6A1CBE01D05F
:1001400020D0BE6A1CC003F01B501CAE08D0000EAD
:10015000D8801B54006E000E1C54036E0050296E94
:1001600003C02AF02A3229322A3229322A3229C0FF
:10017000BBFF2A322A30300B006EBA50CF0B001072
:10018000BA6E9E9630EF00F04376616B2E0D0A003A
:10019000486D6D2E2E2E254C640D0A00939E8A9E6E
:1001A000080E016E00D00000018E0ED0019E273295
:1001B000D8B08A8ED8A08A9E018C06D0019C012ED0
:1001C000F6D700D000008A8E3F0EE96EE92EFED7EA
:1001D000000001BEEBD701BCF1D7000C0900F552BD
:1001E0000CE0F6CF1EF0F7CF1FF0F5CF27F0D6DFEB
:1001F0001EC0F6FF1FC0F7FFF1D7E7EF01F00900BF
:10020000F6CF1FF0F7CF20F0F5CF27F0C7DF1FC0E4
:10021000F6FF20C0F7FF1E2EF2D7F0EF01F0EACF75
:1002200026F0E9CF25F01FAE08D0258E25A8252A77
:100230001E1E1F1E1E2AD8B41F2A1F38F009216E49
:100240002126E20F226E320F246E1F500F0B222642
:1002500022262426E90F236E232623261E380F0B81
:100260002326242623362436241E24361E500F0B24
:1002700024262136070E206E0A0E23062426FDE3CF
:1002800022062326FDE321062226FDE32006212661
:10029000FDE3EA6A200EE96E070E2514259CE906A7
:1002A000251407E125B8E92A25B803D0200E006EF1
:1002B0001CD0E926240EE95CD8B4258CEF50006EE2
:1002C00008E125BC06D025B81BD025B602D0200EEB
:1002D0000BD025AE06D02D0E006EED50259C259E30
:1002E00004D025862598300E0026EACF1FF0E9CFEE
:1002F0001EF000C027F052DF1FC0EAFF1EC0E9FF5A
:10030000EE5025ACD7D7F7EF01F0EA6A1F0EE96E81
:10031000EF500DE0020E016E006A002EFED7012E96
:10032000FBD7970E006E002EFED7EF2EF3D7000CF2
:10033000F86AD09E078EEA6AE96A700ED36ED350CF
:10034000939E8A8E93829380A20EC86E360EC66EDE
:10035000C150C00B0F09C16E070EB46E030E1D6EA7
:10036000720ED36ED350C150C00B0F09C16EC09036
:10037000C092C094C09EC2809698D190800ED56ED7
:10038000CD6A000E0609CA6EFF0ECB6EB16A949458
:100390008B94969C0C0EBD6EB76AB66A94928B9243
:1003A000BA6EBE6ABB6A070EB46E9250926E060EAB
:1003B000006E002EFED70000B450A19CB56A9D8649
:1003C000C00EF212880EF66E010EF76E07D71C6A89
:1003D0001B6A900EF66E010EF76E060E1E6E0FD79C
:1003E000100EE96E1CC01FF01BC01EF018D70D0EBA
:1003F000276ED4DE0A0E276ED1DE92928992020E0B
:100400001E6EFA0E1F6E81DF1E2EFBD7929289821E
:1004100092948984020E1E6EFA0E1F6E76DF1E2ED7
:06042000FBD7D7D7030053
:020000040030CA
:0E00000027C9380E0087A1000FC00FE00F4087
:00000001FF
;PIC18F4550
;CRC=ECFC CREATED="25-5-14 22:48"